-
-
Notifications
You must be signed in to change notification settings - Fork 80
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
Issue with CORS when response is cached #242
Comments
Love the detailed writeup! Super helpful - should be fixed in |
If anyone is still having issues with this in const { preflight, corsify } = cors();
type CFArgs = [Env, ExecutionContext];
// Do not corsify for redirections
const wrappedCorsify = (response: Response, request?: Request): Response => {
if (response?.status === 302) {
return response;
}
return corsify(response, request);
};
const router = AutoRouter<IRequest, CFArgs>({
before: [preflight],
finally: [wrappedCorsify]
});
router
.get('/authorize', (request, env) => {
return Response.redirect(
`https://github.com/login/oauth/authorize?client_id=${env.GITHUB_OAUTH_APP_CLIENT_ID}&scope=gist`,
302
);
}
); |
Hello, we're having the same issue in Cloudflare for almost every response with After investigating, the solution that worked for us was to create a new response in |
Describe the Issue
Cached responses throws error when corsify is in use. Non cached responses work well.
Example Router Code
Request Details
/hello
Steps to Reproduce
Steps to reproduce the behavior:
/hello
, first response is not cachedExpected Behavior
Expected to have a cached response with no errors and cors applied when necessary, same behaviour from router-itty 4 with corsify
Actual Behavior
An error is thrown if the request is cached and the request fails.
Environment (please complete the following information):
Workaround
A workaround. Not calling corsify if the response is cached. To check if it's a cached response, just see if a header not added by you is present in the cached response.
The text was updated successfully, but these errors were encountered: