From 0d09e37af21e00da0b2326e270f5ef0cb08fb8f7 Mon Sep 17 00:00:00 2001 From: Brandon Wolfgang Date: Wed, 21 Oct 2026 17:06:21 -0500 Subject: [PATCH] refactor: export Fastify app factory for testing - Extract route and server configuration into an exported buildApp function - Guard server startup so importing the module does not automatically listen on port 3000 - Preserve health and readiness endpoints and loopback-only binding - Normalize string literals to double quotes --- src/server.ts | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/server.ts b/src/server.ts index b27bccc..4730318 100644 --- a/src/server.ts +++ b/src/server.ts @@ -1,24 +1,30 @@ -import Fastify from 'fastify'; +import Fastify from "fastify"; -const app = Fastify({ - logger: true, -}); +export const buildApp = () => { + const app = Fastify({ + logger: true, + }); -app.get('/health', async () => ({ - status: 'ok', -})); + app.get("/health", async () => ({ + status: "ok", + })); -app.get('/ready', async () => ({ - status: 'ready', - dependencies: { - ollama: 'not-integrated', - }, -})); + app.get("/ready", async () => ({ + status: "ready", + dependencies: { + ollama: "not-integrated", + }, + })); + + return app; +}; const start = async () => { + const app = buildApp(); + try { await app.listen({ - host: '127.0.0.1', + host: "127.0.0.1", port: 3000, }); } catch (error) { @@ -27,4 +33,6 @@ const start = async () => { } }; -void start(); +if (import.meta.url === `file://${process.argv[1]}`) { + void start(); +}