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 = () => {
const app = Fastify({
logger: true,
});
});
app.get('/health', async () => ({
status: 'ok',
}));
app.get("/health", async () => ({
status: "ok",
}));
app.get('/ready', async () => ({
status: 'ready',
app.get("/ready", async () => ({
status: "ready",
dependencies: {
ollama: 'not-integrated',
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();
}