UNPKG

cube-ms

Version:

Production-ready microservice framework with health monitoring, validation, error handling, and Docker Swarm support

16 lines (12 loc) 357 B
export function validateApiKey(apiKeys) { return function (req, res, next) { const apiKey = req.headers["x-api-key"]; if (!apiKey) { return res.status(401).json({ error: "API Key is required" }); } if (!apiKeys.includes(apiKey)) { return res.status(401).json({ error: "API Key is not valid" }); } next(); }; }