From 6a3824fbb0d5538af2a3c9a9fc578575ec9d96f5 Mon Sep 17 00:00:00 2001 From: Gift Amadi <120387225+giftexceed@users.noreply.github.com> Date: Mon, 22 Jun 2026 15:40:01 +0000 Subject: [PATCH] fix(listener): return after handling GET /api/preferences/:userId The GET preferences handler wrote its response but did not return, so execution fell through to the catch-all 404 handler, which called res.writeHead() again and threw "Cannot write headers after they are sent to the client". Add the explicit 200 + JSON content-type header and return after responding, matching the other route handlers. Fixes the failing "GET /api/preferences/:userId returns preferences for the given user" test in events-server.test.ts. --- listener/src/api/events-server.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/listener/src/api/events-server.ts b/listener/src/api/events-server.ts index 197e189..a99fbb7 100644 --- a/listener/src/api/events-server.ts +++ b/listener/src/api/events-server.ts @@ -484,7 +484,9 @@ export function createEventsServer(options: EventsServerOptions): http.Server { const userId = decodeURIComponent(getPrefsMatch[1]); logger.info('Handling GET /api/preferences/:userId', { requestId, correlationId, userId }); const prefs = preferenceStore.get(userId); + res.writeHead(200, { 'Content-Type': 'application/json' }); res.end(JSON.stringify(prefs)); + return; } // PUT /api/preferences/:userId