From 51a71ccc78f47c1d11bc8704c884bca58840aa70 Mon Sep 17 00:00:00 2001 From: Torben Sorensen Date: Sun, 23 Nov 2025 13:37:07 -0800 Subject: [PATCH] tests cannot connect to db --- server.ts | 24 +++++++++++++++++++++++- src/routes/ai.ts | 2 ++ src/services/apiClient.ts | 2 +- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/server.ts b/server.ts index d55c6e6b..55b86c23 100644 --- a/server.ts +++ b/server.ts @@ -125,4 +125,26 @@ app.use((err: Error, req: Request, res: Response, next: NextFunction) => { const PORT = process.env.PORT || 3001; app.listen(PORT, () => { logger.info(`Authentication server started on port ${PORT}`); -}); \ No newline at end of file +}); + +// --- START ROUTE DEBUGGING --- +// On server startup, print all registered routes to the console. +// This helps debug 404s by showing exactly what Express thinks the routes are. +const routes: { method: string, path: string }[] = []; +app._router.stack.forEach((middleware: any) => { + if (middleware.route) { // routes registered directly on the app + routes.push({ + method: Object.keys(middleware.route.methods).join(', ').toUpperCase(), + path: middleware.route.path + }); + } else if (middleware.name === 'router') { // router instances + middleware.handle.stack.forEach((handler: any) => { + const route = handler.route; + route && routes.push({ method: Object.keys(route.methods).join(', ').toUpperCase(), path: `${middleware.regexp.source.replace('\\/?(?=\\/|$)', '').slice(1)}${route.path}`}); + }); + } +}); +console.log('--- REGISTERED API ROUTES ---'); +console.table(routes); +console.log('-----------------------------'); +// --- END ROUTE DEBUGGING --- \ No newline at end of file diff --git a/src/routes/ai.ts b/src/routes/ai.ts index e4b02638..c0a143b2 100644 --- a/src/routes/ai.ts +++ b/src/routes/ai.ts @@ -44,6 +44,8 @@ router.post('/process-flyer', optionalAuth, upload.array('flyerImages'), async ( mimetype: file.mimetype })); + logger.debug(`[API /ai/process-flyer] Processing image paths:`, { imagePaths }); + const user = req.user as UserProfile | undefined; const logIdentifier = user ? `user ID: ${user.id}` : 'anonymous user'; diff --git a/src/services/apiClient.ts b/src/services/apiClient.ts index e65e807e..1f8fa43c 100644 --- a/src/services/apiClient.ts +++ b/src/services/apiClient.ts @@ -1280,7 +1280,7 @@ export async function deleteUserAccount(password: string, tokenOverride?: string errorMessage = data.message || errorMessage; } catch (e) { // Response was not JSON (likely 404 HTML or 500 text) - const text = await response.text(); + const text = await response.clone().text(); // Use clone() to avoid "Body already read" error logger.error(`deleteUserAccount failed with status ${response.status}. Body: ${text}`); errorMessage += `: ${response.status} ${response.statusText}`; }