Skip to content

Commit 6726bf8

Browse files
committed
Add support for bearer token auth on metrics endpoint
1 parent d4813a2 commit 6726bf8

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

apps/webapp/app/routes/metrics.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ import { prisma } from "~/db.server";
33
import { metricsRegister } from "~/metrics.server";
44

55
export async function loader({ request }: LoaderFunctionArgs) {
6+
// If the TRIGGER_METRICS_AUTH_PASSWORD is set, we need to check if the request has the correct password in auth header
7+
const authPassword = process.env.TRIGGER_METRICS_AUTH_PASSWORD;
8+
9+
if (authPassword) {
10+
const auth = request.headers.get("Authorization");
11+
if (auth !== `Bearer ${authPassword}`) {
12+
return new Response("Unauthorized", { status: 401 });
13+
}
14+
}
15+
616
const prismaMetrics = await prisma.$metrics.prometheus();
717
const coreMetrics = await metricsRegister.metrics();
818

0 commit comments

Comments
 (0)