mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
* refactor media-type next.js API resource to mitigate request forgery attack * fix typescript
18 lines
569 B
TypeScript
18 lines
569 B
TypeScript
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
import * as promClient from 'prom-client';
|
|
|
|
const isEnabled = process.env.PROMETHEUS_METRICS_ENABLED === 'true';
|
|
|
|
isEnabled && promClient.collectDefaultMetrics({ prefix: 'frontend_' });
|
|
|
|
export default async function metricsHandler(req: NextApiRequest, res: NextApiResponse) {
|
|
if (!isEnabled) {
|
|
res.status(404).json({ error: 'Not found' });
|
|
return;
|
|
}
|
|
|
|
const metrics = await promClient.register.metrics();
|
|
res.setHeader('Content-type', promClient.register.contentType);
|
|
res.send(metrics);
|
|
}
|