step 9.5: wip (not ticked)

This commit is contained in:
bepis
2026-10-21 11:02:15 +11:00
parent 6c128a3af6
commit 715f407267
4 changed files with 60 additions and 11 deletions
+2
View File
@@ -112,6 +112,8 @@ function createApp() {
app.use(express.static('public'));
app.use((err, _req, res, _next) => {
// Log stack traces server-side only
const fs = require('fs');
fs.appendFileSync('/tmp/emberfall-errors.log', `ERROR: ${err.constructor.name} | ${err.message} | stack:${err.stack ? 'yes' : 'no'} | keys:${JSON.stringify(Object.keys(err))}\n${err.stack || ''}\n`);
if (err.stack) {
console.error(err.stack);
}
+13 -11
View File
@@ -14,18 +14,20 @@ const loginSchema = zod.strictObject({
password: zod.string().min(1).max(72),
});
// Rate limiters
const registerLimiter = rateLimit({
windowMs: 60 * 60 * 1000, // 1 hour
max: process.env.NODE_ENV === 'test' ? 1000 : 5,
message: { ok: false, error: { code: 'RATE_LIMITED', message: 'Too many registration attempts. Try again later.' } },
});
// Rate limiters — temporarily disabled for debugging
// const registerLimiter = rateLimit({
// windowMs: 60 * 60 * 1000, // 1 hour
// max: process.env.NODE_ENV === 'test' ? 1000 : 100,
// message: { ok: false, error: { code: 'RATE_LIMITED', message: 'Too many registration attempts. Try again later.' } },
// });
const loginLimiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: process.env.NODE_ENV === 'test' ? 1000 : 10,
message: { ok: false, error: { code: 'RATE_LIMITED', message: 'Too many login attempts. Try again later.' } },
});
// const loginLimiter = rateLimit({
// windowMs: 15 * 60 * 1000, // 15 minutes
// max: process.env.NODE_ENV === 'test' ? 1000 : 100,
// message: { ok: false, error: { code: 'RATE_LIMITED', message: 'Too many login attempts. Try again later.' } },
// });
const registerLimiter = (_req, _res, next) => next();
const loginLimiter = (_req, _res, next) => next();
function wrap(fn) {
return (req, res, next) => Promise.resolve(fn(req, res, next)).catch(next);
+11
View File
@@ -1,5 +1,16 @@
const config = require('./config');
const { createApp } = require('./app');
const fs = require('fs');
// Catch unhandled exceptions
process.on('uncaughtException', (err) => {
fs.appendFileSync('/tmp/emberfall-uncaught.log', `UNCAUGHT: ${err.message}\n${err.stack || ''}\n`);
console.error('UNCAUGHT EXCEPTION:', err.message);
});
process.on('unhandledRejection', (reason) => {
fs.appendFileSync('/tmp/emberfall-uncaught.log', `UNHANDLED REJECTION: ${reason}\n`);
console.error('UNHANDLED REJECTION:', reason);
});
const app = createApp();