-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetricsController.ts
More file actions
32 lines (28 loc) · 896 Bytes
/
Copy pathmetricsController.ts
File metadata and controls
32 lines (28 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import type { Request, Response } from "express";
import {
metricsContentType,
metricsEnabled,
renderMetrics,
} from "../metrics/authMetrics";
import { env } from "../config/env";
import { extractBearerToken } from "../utils/bearerToken";
export async function metrics(req: Request, res: Response) {
if (!metricsEnabled) {
return res.status(404).json({ message: "metrics disabled" });
}
if (
env.METRICS_AUTH_TOKEN &&
extractBearerToken(req.header("authorization")) !== env.METRICS_AUTH_TOKEN
) {
return res.status(401).json({
error: {
code: "METRICS_AUTHORIZATION_REQUIRED",
message: "metrics authorization is required",
correlationId: req.correlationId,
},
});
}
res.setHeader("Content-Type", metricsContentType);
res.setHeader("Cache-Control", "no-store");
return res.status(200).send(await renderMetrics());
}