-
Notifications
You must be signed in to change notification settings - Fork 48
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
Add setting to yield next on OPTION request #30
Comments
+1 This also makes sense if |
+1 Related:
I was having a problem with OPTIONS in koa-router, if a xhr library sends an OPTIONS request, the koa-cors wouldn't work. I solved it by using the following code: // drop koa-cors
// api cors
apiRouter.use(async (ctx, next) => {
ctx.set('Access-Control-Allow-Credentials', 'true')
ctx.set('Access-Control-Allow-Origin', '*')
await next()
})
// api options method
apiRouter.options('*', async (ctx, next) => {
ctx.set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
ctx.set('Access-Control-Allow-Origin', '*')
ctx.status = 204
await next()
}) |
I had met this problem. And I solved it by setting options foo koa-cors, add
|
@fritx you are missing this from your example above: ctx.set(
'Access-Control-Allow-Headers',
ctx.get('Access-Control-Request-Headers')
); working code: // Instead of using `@koa/cors` which conflicts with `koa-router`:
// https://github.com/evert0n/koa-cors/issues/30#issuecomment-301310688
routes.use(async (ctx, next) => {
ctx.set('Access-Control-Allow-Credentials', 'true');
ctx.set('Access-Control-Allow-Origin', '*');
await next();
});
routes.options('*', async (ctx, next) => {
ctx.set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
ctx.set('Access-Control-Allow-Origin', '*');
ctx.set(
'Access-Control-Allow-Headers',
ctx.get('Access-Control-Request-Headers')
);
ctx.status = 204;
await next();
}); |
In most cases it makes sense to just return a 204 on an OPTIONS request, but the specification says that a body can be included with the response. Could we have some sort of setting that makes the module not capture the OPTIONS request?
To clarify, I need a setting that does something like below:
The text was updated successfully, but these errors were encountered: