fix verification of api key

This commit is contained in:
Darius
2025-11-19 00:54:08 +01:00
parent 039ac46967
commit 43fda0b20a

View File

@@ -1,3 +1,4 @@
import { logInfo } from "@dpu/shared/dist/logger.js";
import type { FastifyReply, FastifyRequest } from "fastify"; import type { FastifyReply, FastifyRequest } from "fastify";
import fastify from "fastify"; import fastify from "fastify";
import fastifyAxios from "fastify-axios"; import fastifyAxios from "fastify-axios";
@@ -23,11 +24,15 @@ await server.register(fastifyAxios, {
}, },
}); });
function verifyAPIKey(request: FastifyRequest, reply: FastifyReply): void { async function verifyAPIKey(
request: FastifyRequest,
reply: FastifyReply,
): Promise<void> {
const apiKey = request.headers["x-api-key"]; const apiKey = request.headers["x-api-key"];
if (!apiKey || apiKey !== Config.api_key) { if (!apiKey || apiKey !== Config.api_key) {
reply.code(401).send({ error: "Invalid API key" }); logInfo("POST Request with wrong API key received");
return reply.code(401).send({ error: "Invalid API key" });
} }
} }