-
Notifications
You must be signed in to change notification settings - Fork 61
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
Add an option to disable CORS proxy #71
Comments
I'll keep this in mind for the rewrite I was intending to start tomorrow ;). I wonder how common the CORS headers are now. I also don't remember what happens if you request something you can't access, if the browser will actually download the whole file (which could be quite large) only to raise an error later. What's the use case for a data URL? |
Thanks! I would consider disabling the proxy an "I know what I'm doing" move so whoever does it would be responsible for any side effects that might occur.
I have Parchment running in an iframe where the main app passes the story file from memory so there's no actual URL it could load. |
Probably the best way would be to just pass in an arraybuffer/uint8array. I'll have a think about whether that should be an overloaded option for default_story or a separate option. |
@juhana Sorry it's taken so long. I remember you saying that you'd like to be able to just pass in a data array, is that still the case? Would that be instead of using a data URL, or would you also need support for a data URL? I'm now thinking there will be a In regards to the proxy server, I'm thinking that it would just try loading the URL, and only if it fails would it try the proxy server. Do you think it really needs an option if that's how it works? |
Sounds good! No need for a data URL if a data array can be passed in.
That system would work for my use cases, but if it's certain that the proxy won't work (e.g. localhost URLs) it'd be cleaner if you could just tell it to not even bother trying the proxy. |
I implemented the above as parchment/src/common/launcher.js Lines 72 to 75 in c8eaa6e
I did change it so that it will try all URLs without the proxy, it no longer assumes other domains don't have proper CORS support. I guess I could add an option to disable the proxy (perhaps by setting the proxy_url to null?) but I doubt it would be useful. If you're in a position where you know the proxy won't work then can't you also ensure the url is correct? Actually, even without changing the code, simply setting the proxy_url to an invalid domain should in effect mean it is never used. It's such a niche use case that I think that might be enough. |
In theory yes, but as long as you can pass the URL as a query parameter you can always have old links pointing to deleted files. If setting the proxy url to null would disable the proxy, that would be the most intuitive way for it to work. (It's the first thing I tried when I tried to disable it.) |
As it is now, I think setting it to |
If you set
Then Parchment won't launch automatically. You can then call
I think your concerns here have basically been handled by now, but if you have any more just make a new issue. |
It's probably not necessary, but I've added a |
Thanks, that'll certainly make things more straightforward! |
Parchment automatically uses a proxy to download the story file if it detects that it's not on the same domain. There are two cases where the proxy makes things worse rather than better:
data:...
)I've been able to get around it with
default_story: "data:text/javascript,processBase64Zcode('....'); // .js"
which tricks Parchment into thinking that it's a legacy .js file, but that's a very hacky solution.Arguably case 2 is a bug and it should detect data URLs, but for case 1 we'd need either that setting the proxy URL option to null would disable it altogether, or a separate setting that disables the proxy. Preferably with options auto-detection (current behavior), always enabled or always disabled. HugoJS has this setting:
The text was updated successfully, but these errors were encountered: