-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
CORS errors during server rendering #8314
Comments
I do experience this issue on your Stackblitz reproduction, but when I download the project and run it locally, I do not. SvelteKit intercepts But in your situation, that check is falsely asserting that the simulated CORS check has failed. But... only on StackBlitz. There are some differences to how Undici and StackBlitz web containers handle fetches... Here's SvelteKit making an SSR {
"user-agent": "undici",
"accept": "*/*",
"accept-encoding": "br, gzip, deflate",
"accept-language": "*",
"origin": "http://127.0.0.1:5173",
"sec-fetch-mode": "cors",
"x-forwarded-for": "47.196.22.77",
"x-forwarded-host": "sveltekit.free.beeceptor.com",
"x-forwarded-proto": "https"
} And here's Firefox making one through StackBlitz: {
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:108.0) Gecko/20100101 Firefox/108.0",
"accept": "*/*",
"accept-encoding": "gzip, deflate, br",
"accept-language": "*",
"cache-control": "no-cache",
"origin": "https://corserrorduringserverrenderrepro-f5o4.w-corp.staticblitz.com",
"pragma": "no-cache",
"referer": "https://corserrorduringserverrenderrepro-f5o4.w-corp.staticblitz.com/",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "cross-site",
"te": "trailers",
"x-forwarded-for": "47.196.22.77",
"x-forwarded-host": "sveltekit.free.beeceptor.com",
"x-forwarded-proto": "https"
} But the weird thing is that both requests are getting the a |
I have the same exact issue on a GitPod repo. I needed to disable Perhaps an |
It might be an issue with the test endpoint in the example since httpbin returns an If someone knows of a test endpoint that sets an |
It seems that the browser removes the We can't fix this without removing the sensible checks to ensure things run on the client and server the same, so I think the best we can do is document this. A workaround (which SvelteKit will warn you about, but you can ignore it in this case) is to use the global |
I am also developing on Gitpod and am running into this issue. I use the same workaround as @Haffi921. |
I am facing same issue. During production there would be different hosts, |
@itssumitrai does the documentation below help resolve your issue? Does setting |
This comment was marked as duplicate.
This comment was marked as duplicate.
Sadly it doesn't work. |
See #8314 (comment) for a full explanation. The recommended workaround for now is to use the global |
Global |
Describe the bug
When fetching an endpoint using CORS from a
+page.js
file, SvelteKit throws a CORS error when trying to render the page on the server, such as during development mode or prerendering for production. CORS doesn't seem to make sense in this context, since the fetch request is being performed on the server, which has no origin.This seems related to #7441, but that issue involved
+page.server.js
files. In this issue, we want to perform the fetch on the client AND the server (during SSR/prerendering).Reproduction
https://stackblitz.com/edit/cors-error-during-server-render-repro?file=src%2Froutes%2Ftest%2F%2Bpage.js
Using the client-side navigation from
/
to/test
fetches data on the client perfectly fine, but doing a browser navigation/reload on the/test
page throws a CORS error on the server. Errors are also thrown when trying to run a build.Logs
No response
System Info
Severity
serious, but I can work around it
Additional Information
No response
The text was updated successfully, but these errors were encountered: