implemented service configuration to API service

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
2026-04-26 14:57:59 +02:00
parent 0964109c4b
commit 747932cf03
2 changed files with 19 additions and 0 deletions
+15
View File
@@ -1,6 +1,7 @@
import { SignJWT, jwtVerify } from "jose";
import env from "dotenv";
import { verifyAPIKeyDB } from "./database.js";
import { checkIfServiceIsActive2 } from "./functions.js";
env.config();
const secretKey = process.env.SECRET_KEY;
@@ -45,6 +46,13 @@ export async function authenticate(req, res, next) {
const apiKey = req.params.key;
if (authHeader) {
const serviceActive = await checkIfServiceIsActive2("User Frontend");
if (!serviceActive) {
return res
.status(503)
.json({ message: "User Frontend is currently unavailable." });
}
const parts = authHeader.split(" ");
const scheme = parts[0];
const token = parts[1];
@@ -61,6 +69,13 @@ export async function authenticate(req, res, next) {
return res.status(403).json({ message: "Present token invalid" }); // present token invalid
}
} else if (apiKey) {
const serviceActive = await checkIfServiceIsActive2("API");
if (!serviceActive) {
return res
.status(503)
.json({ message: "API Service is currently unavailable." });
}
try {
await verifyAPIKey(apiKey);
return next();