UNPKG

legendaryjs

Version:

LegendaryJS – The ultimate backend framework for speed, power, and simplicity.

18 lines (12 loc) 503 B
const path = require('path'); const config = require(path.join(process.cwd(), 'legendary.config.js')); function apiKeyMiddleware(req, res, next) { if (!config.authorization?.apiKey) return next(); const apiKey = req.headers['x-api-key']; const validKeys = process.env.API_KEYS?.split(',') || []; if (!apiKey || !validKeys.includes(apiKey)) { return res.status(401).json({ message: 'Invalid or missing API key' }); } next(); } module.exports = { apiKeyMiddleware };