mirror of
https://github.com/jina-ai/node-DeepResearch.git
synced 2026-03-22 07:29:35 +08:00
fix: add early API key validation
This commit is contained in:
@@ -74,6 +74,16 @@ export const jinaAiMiddleware = (req: Request, res: Response, next: NextFunction
|
|||||||
next();
|
next();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Early API key validation - reject immediately if no valid auth header
|
||||||
|
const authHeader = req.headers.authorization;
|
||||||
|
if (!authHeader || !authHeader.startsWith('Bearer ')) {
|
||||||
|
corsMiddleware(req, res, () => {
|
||||||
|
res.status(401).json({ error: 'Unauthorized: API key required' });
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
asyncLocalContext.run(async () => {
|
asyncLocalContext.run(async () => {
|
||||||
const googleTraceId = req.get('x-cloud-trace-context')?.split('/')?.[0];
|
const googleTraceId = req.get('x-cloud-trace-context')?.split('/')?.[0];
|
||||||
const ctx = asyncLocalContext.ctx;
|
const ctx = asyncLocalContext.ctx;
|
||||||
|
|||||||
Reference in New Issue
Block a user