diff --git a/src/index.ts b/src/index.ts index 5731b05..8ebd9d5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,4 @@ +import { logInfo } from "@dpu/shared/dist/logger.js"; import type { FastifyReply, FastifyRequest } from "fastify"; import fastify from "fastify"; 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 { const apiKey = request.headers["x-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" }); } }