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(); +}