mirror of
https://github.com/jina-ai/node-DeepResearch.git
synced 2025-12-26 06:28:56 +08:00
jina-ai: fix cors
This commit is contained in:
parent
970167245e
commit
507bc38546
@ -10,6 +10,7 @@ import asyncLocalContext from "./lib/async-context";
|
|||||||
import globalLogger from "./lib/logger";
|
import globalLogger from "./lib/logger";
|
||||||
import { InsufficientBalanceError } from "./lib/errors";
|
import { InsufficientBalanceError } from "./lib/errors";
|
||||||
import { FirestoreRecord } from "./lib/firestore";
|
import { FirestoreRecord } from "./lib/firestore";
|
||||||
|
import cors from "cors";
|
||||||
|
|
||||||
globalLogger.serviceReady();
|
globalLogger.serviceReady();
|
||||||
const logger = globalLogger.child({ service: 'JinaAISaaSMiddleware' });
|
const logger = globalLogger.child({ service: 'JinaAISaaSMiddleware' });
|
||||||
@ -59,7 +60,7 @@ export class KnowledgeItem extends FirestoreRecord {
|
|||||||
})
|
})
|
||||||
updatedAt!: Date;
|
updatedAt!: Date;
|
||||||
}
|
}
|
||||||
|
const corsMiddleware = cors();
|
||||||
export const jinaAiMiddleware = (req: Request, res: Response, next: NextFunction) => {
|
export const jinaAiMiddleware = (req: Request, res: Response, next: NextFunction) => {
|
||||||
if (req.path === '/ping') {
|
if (req.path === '/ping') {
|
||||||
res.status(200).end('pone');
|
res.status(200).end('pone');
|
||||||
@ -141,6 +142,7 @@ export const jinaAiMiddleware = (req: Request, res: Response, next: NextFunction
|
|||||||
|
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
if (!res.headersSent) {
|
if (!res.headersSent) {
|
||||||
|
corsMiddleware(req, res, () => 'noop');
|
||||||
if (err instanceof ApplicationError) {
|
if (err instanceof ApplicationError) {
|
||||||
res.status(parseInt(err.code as string) || 500).json({ error: err.message });
|
res.status(parseInt(err.code as string) || 500).json({ error: err.message });
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user