feat: add daemon server skeleton with health check endpoint
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import http from 'node:http';
|
||||
import { healthRoute } from './routes/health.js';
|
||||
|
||||
const routes = [healthRoute];
|
||||
|
||||
export function startServer(port: number): Promise<http.Server> {
|
||||
return new Promise((resolve) => {
|
||||
const server = http.createServer((req, res) => {
|
||||
for (const route of routes) {
|
||||
if (route(req, res)) return;
|
||||
}
|
||||
res.writeHead(404, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify({ ok: false, error: { code: 'INTERNAL', message: 'not found' } }));
|
||||
});
|
||||
|
||||
server.listen(port, '127.0.0.1', () => {
|
||||
console.log(`[daemon] VisionL daemon started on http://127.0.0.1:${port}`);
|
||||
resolve(server);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Direct start when running as script
|
||||
const port = parseInt(process.env.VISIONL_PORT || '9527', 10);
|
||||
startServer(port);
|
||||
Reference in New Issue
Block a user