Github pages and CORS #22399
|
Hello, But when the page from github pages tries to access the data, the browser console shows The server has CORS enabled (it is the loopback 4 framework that has CORS enabled by default). Is there anything I need to do in the app under GH? |
Replies: 12 comments 1 reply
|
Hello, Does your Pages site has its visibility set to private? Pages allows CORS ( This is the current (sensitive) behavior in place until we can support custom headers. |
|
No the site is public. |
|
Only thing I can think of is extra restrictions your browser would put on. Say if |
|
The server VM is local but within the code on github, it points to my ISP allocated IP address and the port forwarding gets it to the VM. |
|
I have added “mode” (cors) to the fetch request along with a header of “Access-Control-Allow-Origin” (the IP address of my ISP connection).
Now this is the first time I have had a reason that mentioned Access-Control-Allow-Origin. It is also the first time that I specifically added Access-Control-Allow-Origin to the headers in the fetch request. Which is all very confusing. |
|
|
|
@airtower-luna, thank you for this. |
|
So I solved this. Nothing to do with github pages or svelte. |
|
Can you be more precise about how you solved this problem |
|
Hello @Sam-cudo, I have two entries for CORS because the frontend code is either running on a local svelte server (localhost/PC) or on github. I hope this helps. The key thing for me was realising that the backend had to know where to expect requests to come from; in my case either github.io or my local svelte server (or apache or nginx or whatever) |
|
Any update about it? |
|
I'm running into issues with this too- I'm using a custom CNAME for my pages site (intangiblematter.net) and I'm getting info about the request being blocked. I'm trying to request from the Bluesky API. Is it possible that there's some thing in requesting that I'm missing? For reference, this is my request // searchParams is just a URLSearchParams object for the request.
const searchResponse = await fetch(
`https://public.api.bsky.app/xrpc/app.bsky.feed.searchPosts?${searchParams}`,
{
headers: {
Accept: "application/json",
// as you can see I've been trying various things and they haven't been working
origin: "https://intangiblematter.github.io",
Referer: "https://intangiblematter.github.io",
},
},
); |
So I solved this. Nothing to do with github pages or svelte.
I was using the cors origin value in the rest server as the url of the server. It needs to be the github.io url.