-
Notifications
You must be signed in to change notification settings - Fork 7
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
Figure out a way around CORS #63
Comments
I'm confused. I don't see the problem in the first place. The website already fetches json files from different channels (i.e. different origins) in the client browser. In fact, GitHub does set curl --header "Origin: https://example.org" -I "https://memo33.github.io/sc4pac/channel/sc4pac-channel-contents.json" Response:
|
Alright, I see what's happening. I never actually tried it with the default channel, only with https://sebamarynissen.github.io/simtropolis-channel/sc4pac-channel-contents.json. However, GitHub redirects this response to https://sc4pac.sebamarynissen.dev/sc4pac-channel-contents.json because I have mapped that domain to it, but it does not include the
I think we're safe then. I will verify and close if confirmed. |
Verified, and it does work indeed. |
I had the same problem while trying to fetch the exchange IDs mapping lists for my browser extension. I used JSDeliver feature to wrap a request in valid headers. |
@Zasco I think we should avoid relying on my manually curated list of available packages in sebamarynissen/sc4pac-helpers and go with the approach of directly fetching the channels instead, as @memo33 also mentioned in sebamarynissen/sc4pac-helpers#4. I don't plan on keeping that list up to date forever, and it kind of defeats the purpose of having everything automated as much as possible. Relying on the channels itself is by definition the only reliable way to tell whether a package can be installed or not, plus it has the benefit of not throwing any CORS errors. |
Already planned (Zasco/sc4pac-browser-extension#1). I might even do it today... It was just so you know about this service if you ever face that problem again. |
Now that the Simtropolis channel is nicely filling up, I started playing a bit with what a script could look like that would add an "Install with sc4pac" button to the STEX upload. You can find the proof of concept below. It is extremely basic and doesn't include things like caching the channel contents - which definitely should be done, neither does it support both the default and simtropolis channel - but it shows what the basic structure might look like.
Proof of concept
There is however one big problem with this approach: you get a CORS error if you use the default channel url:
This can be solved by sending the
Access-Control-Allow-Origin: *
header, but unfortunately GitHub pages does not support setting custom headers. There are a few solutions to this problem:1. Move the default channel to sc4pac.com
This is my preferred solution.
Pros
Access-Control-Allow-Origin: *
header. This is what I did to get the proof of concept working with sc4pac.sebamarynissen.devCons
2. Move the deployment to CloudFlare pages
Pros
_headers
file where you can customize the headers.Cons
3. Provide the channel as
.js
file with JSONPA way around CORS is that you could load the channel in a
<script>
tag. Hence, along withsc4pac-channel-contents.json
, the channel could also provide something likesc4pac-channel-contents.js
which looks likeThe calling script should provide a global
loadChannel()
function in that case.Pros
<script src="https://memo33.github.io/sc4pac/channel/sc4pac-channel-contents.js">
.Cons
sc4pac-channel-contents.js
4. Limit integration to a browser plugin
I'm not entirely sure, but I suppose you can get around the CORS limitations when making the request as a browser plugin service worker, rather than a content script.
Pros
Cons
@Zasco you might be interested in this as well, as it's also relevant for your plugin I guess
The text was updated successfully, but these errors were encountered: