-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable Cors for all routes #72
Comments
By class inheritance or middleware (in nextjs you can place _middleware.ts in pages or api directory for instance). Your demand is not quite related to the library itself. |
@gmariusze your response makes the library less useful. The developer should explain how his library is useful, explaining how to implement it in projects. |
I dont understand what was was wrong with the response, the author's response makes sense to me here |
@yonycalsin The method signature for middlewares in NextJS |
You can read this blog post to use CORS for all routes with it. You can see the repository you can use as an example here. You can use this instead of the handler from Next js. import NextCors from 'nextjs-cors';
function withNextCors(
handler: NextApiHandler,
): NextApiHandler {
return async function nextApiHandlerWrappedWithNextCors(req, res) {
const methods = ['GET', 'HEAD', 'PUT', 'PATCH', 'POST', 'DELETE'];
await NextCors(req, res, {
methods,
origin: CORS_ALLOWED_ORGIN,
optionsSuccessStatus: 200,
});
return handler(req, res);
};
} |
whats inside CORS_ALLOWED_ORGIN ? |
I suppose it's an array of strings: CORS_ALLOWED_ORGIN = ['http://localhost:5173',] |
I see from the example that I can enable cors for that specific route -
api/whoami
but is there a way to apply this to all routes?The text was updated successfully, but these errors were encountered: