feat(server): healthz, testable app, local dev script (P0-3)

This commit is contained in:
Benjamin Oezcan
2026-11-19 01:40:31 +01:00
parent 35348324d6
commit fa68ef620d
8 changed files with 1465 additions and 16 deletions

23
server/test/helpers.js Normal file
View File

@@ -0,0 +1,23 @@
/* Test helpers: start the real server on a random port with an in-memory database. */
'use strict';
process.env.NODE_ENV = 'test';
process.env.DB_FILE = ':memory:';
delete process.env.JWT_SECRET;
const { listen } = require('../app');
async function startServer() {
const srv = await listen(0);
const base = 'http://127.0.0.1:' + srv.address().port;
const json = async (method, path, body, token) => {
const res = await fetch(base + path, {
method,
headers: Object.assign({ 'Content-Type': 'application/json' }, token ? { Authorization: 'Bearer ' + token } : {}),
body: body === undefined ? undefined : JSON.stringify(body),
});
return { status: res.status, body: await res.json().catch(() => null) };
};
return { base, json, close: () => new Promise(r => { srv.closeAllConnections(); srv.close(r); }) };
}
module.exports = { startServer };