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";
|
||||
|
||||
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 () => {
|
|||
}
|
||||
};
|
||||
|
||||
if (import.meta.url === `file://${process.argv[1]}`) {
|
||||
void start();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue