step 9.5: wip (not ticked)
This commit is contained in:
@@ -112,6 +112,8 @@ function createApp() {
|
|||||||
app.use(express.static('public'));
|
app.use(express.static('public'));
|
||||||
app.use((err, _req, res, _next) => {
|
app.use((err, _req, res, _next) => {
|
||||||
// Log stack traces server-side only
|
// 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) {
|
if (err.stack) {
|
||||||
console.error(err.stack);
|
console.error(err.stack);
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-11
@@ -14,18 +14,20 @@ const loginSchema = zod.strictObject({
|
|||||||
password: zod.string().min(1).max(72),
|
password: zod.string().min(1).max(72),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Rate limiters
|
// Rate limiters — temporarily disabled for debugging
|
||||||
const registerLimiter = rateLimit({
|
// const registerLimiter = rateLimit({
|
||||||
windowMs: 60 * 60 * 1000, // 1 hour
|
// windowMs: 60 * 60 * 1000, // 1 hour
|
||||||
max: process.env.NODE_ENV === 'test' ? 1000 : 5,
|
// max: process.env.NODE_ENV === 'test' ? 1000 : 100,
|
||||||
message: { ok: false, error: { code: 'RATE_LIMITED', message: 'Too many registration attempts. Try again later.' } },
|
// message: { ok: false, error: { code: 'RATE_LIMITED', message: 'Too many registration attempts. Try again later.' } },
|
||||||
});
|
// });
|
||||||
|
|
||||||
const loginLimiter = rateLimit({
|
// const loginLimiter = rateLimit({
|
||||||
windowMs: 15 * 60 * 1000, // 15 minutes
|
// windowMs: 15 * 60 * 1000, // 15 minutes
|
||||||
max: process.env.NODE_ENV === 'test' ? 1000 : 10,
|
// max: process.env.NODE_ENV === 'test' ? 1000 : 100,
|
||||||
message: { ok: false, error: { code: 'RATE_LIMITED', message: 'Too many login attempts. Try again later.' } },
|
// 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) {
|
function wrap(fn) {
|
||||||
return (req, res, next) => Promise.resolve(fn(req, res, next)).catch(next);
|
return (req, res, next) => Promise.resolve(fn(req, res, next)).catch(next);
|
||||||
|
|||||||
@@ -1,5 +1,16 @@
|
|||||||
const config = require('./config');
|
const config = require('./config');
|
||||||
const { createApp } = require('./app');
|
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();
|
const app = createApp();
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
const SessionStore = require('better-sqlite3-session-store')(require('express-session'));
|
||||||
|
const { getDb } = require('./src/db');
|
||||||
|
|
||||||
|
try {
|
||||||
|
const db = getDb();
|
||||||
|
// Check if sessions table exists
|
||||||
|
const tables = db.prepare("SELECT name FROM sqlite_master WHERE type='table'").all();
|
||||||
|
console.log('Tables:', tables.map(t => t.name));
|
||||||
|
|
||||||
|
// Try creating a session
|
||||||
|
const store = new SessionStore({
|
||||||
|
client: db,
|
||||||
|
table: 'sessions',
|
||||||
|
expired: { clear: false },
|
||||||
|
});
|
||||||
|
|
||||||
|
// Try creating a session
|
||||||
|
const session = { userId: 1, username: 'test' };
|
||||||
|
store.set('test-session-id', session, (err) => {
|
||||||
|
if (err) {
|
||||||
|
console.log('SET ERROR:', err.message);
|
||||||
|
console.log('ERROR STACK:', err.stack);
|
||||||
|
} else {
|
||||||
|
console.log('SET OK');
|
||||||
|
store.get('test-session-id', (err2, data) => {
|
||||||
|
if (err2) console.log('GET ERROR:', err2.message);
|
||||||
|
else console.log('GET DATA:', JSON.stringify(data));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.log('CATCH ERROR:', e.message);
|
||||||
|
console.log('STACK:', e.stack);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user