mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-27 00:17:31 +00:00
16 lines
471 B
TypeScript
16 lines
471 B
TypeScript
import type { NextApiResponse, NextApiRequest } from 'next';
|
|
import NextCors from 'nextjs-cors';
|
|
|
|
export async function withNextCors(req: NextApiRequest, res: NextApiResponse) {
|
|
const methods = ['GET', 'eHEAD', 'PUT', 'PATCH', 'POST', 'DELETE'];
|
|
|
|
const allowedOrigins = process.env.ALLOWED_ORIGINS?.split(',');
|
|
const origin = req.headers.origin;
|
|
|
|
await NextCors(req, res, {
|
|
methods,
|
|
origin: allowedOrigins || origin,
|
|
optionsSuccessStatus: 200
|
|
});
|
|
}
|