mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-20 19:24:29 +00:00
20 lines
558 B
TypeScript
20 lines
558 B
TypeScript
import type { NextApiResponse, NextApiHandler, NextApiRequest } from 'next';
|
|
import NextCors from 'nextjs-cors';
|
|
|
|
export function withNextCors(handler: NextApiHandler): NextApiHandler {
|
|
return async function nextApiHandlerWrappedWithNextCors(
|
|
req: NextApiRequest,
|
|
res: NextApiResponse
|
|
) {
|
|
const methods = ['GET', 'eHEAD', 'PUT', 'PATCH', 'POST', 'DELETE'];
|
|
const origin = req.headers.origin;
|
|
await NextCors(req, res, {
|
|
methods,
|
|
origin: origin,
|
|
optionsSuccessStatus: 200
|
|
});
|
|
|
|
return handler(req, res);
|
|
};
|
|
}
|