Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Not all OPTIONS requests are CORS preflight requests from browsers. This middleware correctly checks to make sure that
Access-Control-Request-Method
is present before fully treating a request as a preflight-- however, it does so after skipping over any of the usual logic for "actual" requests.The result is that access control headers will not be set for any OPTIONS requests, even though they will still continue into downstream middlewares like other "actual" requests:
cors/index.js
Lines 101 to 107 in 71c4d00
This blocks any and all cross-origin OPTIONS requests that are not preflights, breaking features in other popular Koa middlewares-- such as the automatic 'allowed methods' middlewares from koa-router-- when accessed cross-origin.
I've fixed the problem by moving this check into the if statement that separates "actual" requests from preflight ones.
I've also removed some unnecessary
await
keywords, rationale explained here:https://eslint.org/docs/rules/no-return-await
I can of course live without this second bit if you guys have some reason I'm not aware of for wanting to
return await
in these scenarios. Any performance change will be far below noticeable. I just figured I might as well, and can roll it back if I have to. 👍Thanks!