Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
createServer(async (req: IncomingMessage, res: ServerResponse): Promise =>
{
try
{
if (parse(req.url ?? '').pathname === '/metrics')
{
const metrics: object[][] = await manager.broadcastEval('this.getMetrics()');
res.writeHead(200, { 'content-type': register.contentType });
res.write(AggregatorRegistry.aggregate(metrics).metrics());
}
else
{
res.writeHead(404, { 'content-type': register.contentType });
res.write('Route not found');
}
}
catch (e)
{
webhook.error('Prometheus', 'Manager', e);
res.writeHead(500, { 'content-type': register.contentType });
res.write('Internal Server Error');
}
res.end();
}).listen(httpPort, () => webhook.info('Prometheus', 'Manager', 'Listening for requests...'));