| 11 | import type { Request, Response, NextFunction } from 'express' |
| 12 | |
| 13 | function getValidKeys(): Set<string> | null { |
| 14 | const multi = process.env.GODMODE_API_KEYS |
| 15 | if (multi) { |
| 16 | return new Set(multi.split(',').map(k => k.trim()).filter(Boolean)) |
| 17 | } |
| 18 | const single = process.env.GODMODE_API_KEY |
| 19 | if (single) { |
| 20 | return new Set([single.trim()]) |
| 21 | } |
| 22 | return null // Auth disabled |
| 23 | } |
| 24 | |
| 25 | export function apiKeyAuth(req: Request, res: Response, next: NextFunction): void { |
| 26 | const validKeys = getValidKeys() |