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
This commit is contained in:
Brandon Wolfgang 2026-10-21 17:06:21 -05:00
parent ed9259d35e
commit 0d09e37af2

View file

@ -1,24 +1,30 @@
import Fastify from 'fastify'; import Fastify from "fastify";
const app = Fastify({ export const buildApp = () => {
logger: true, const app = Fastify({
}); logger: true,
});
app.get('/health', async () => ({ app.get("/health", async () => ({
status: 'ok', status: "ok",
})); }));
app.get('/ready', async () => ({ app.get("/ready", async () => ({
status: 'ready', status: "ready",
dependencies: { dependencies: {
ollama: 'not-integrated', ollama: "not-integrated",
}, },
})); }));
return app;
};
const start = async () => { const start = async () => {
const app = buildApp();
try { try {
await app.listen({ await app.listen({
host: '127.0.0.1', host: "127.0.0.1",
port: 3000, port: 3000,
}); });
} catch (error) { } catch (error) {
@ -27,4 +33,6 @@ const start = async () => {
} }
}; };
void start(); if (import.meta.url === `file://${process.argv[1]}`) {
void start();
}