fix verification of api key
This commit is contained in:
@@ -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" });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user