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:
parent
ed9259d35e
commit
0d09e37af2
1 changed files with 23 additions and 15 deletions
|
|
@ -1,24 +1,30 @@
|
||||||
import Fastify from 'fastify';
|
import Fastify from "fastify";
|
||||||
|
|
||||||
const app = Fastify({
|
export const buildApp = () => {
|
||||||
|
const app = Fastify({
|
||||||
logger: true,
|
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();
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue