Update ESLint rules, enhance environment schema with new metrics and health port, and refactor Redis import. Change TypeScript definitions path in package.json.
This commit is contained in:
32
apps/bot/src/health.ts
Normal file
32
apps/bot/src/health.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { createServer } from 'node:http';
|
||||
import { env } from './env.js';
|
||||
|
||||
export function startHealthServer(): void {
|
||||
const server = createServer((req, res) => {
|
||||
if (!req.url) {
|
||||
res.statusCode = 400;
|
||||
res.end('Bad Request');
|
||||
return;
|
||||
}
|
||||
if (req.url === '/health') {
|
||||
res.statusCode = 200;
|
||||
res.end('ok');
|
||||
return;
|
||||
}
|
||||
if (req.url === '/metrics') {
|
||||
const auth = req.headers.authorization;
|
||||
if (!env.METRICS_TOKEN || auth !== `Bearer ${env.METRICS_TOKEN}`) {
|
||||
res.statusCode = 401;
|
||||
res.end('Unauthorized');
|
||||
return;
|
||||
}
|
||||
res.statusCode = 200;
|
||||
res.end('# Prometheus metrics scaffold\nnexumi_up 1\n');
|
||||
return;
|
||||
}
|
||||
res.statusCode = 404;
|
||||
res.end('Not Found');
|
||||
});
|
||||
|
||||
server.listen(env.HEALTH_PORT);
|
||||
}
|
||||
Reference in New Issue
Block a user