Skip to content
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

Implement CORS / preflight support in the dev server #9357

Open
marcins opened this issue Nov 2, 2023 · 3 comments
Open

Implement CORS / preflight support in the dev server #9357

marcins opened this issue Nov 2, 2023 · 3 comments

Comments

@marcins
Copy link
Contributor

marcins commented Nov 2, 2023

🙋 feature request

Currently the Parcel dev server only responds to GET and HEAD requests, so does not respond to CORS preflight requests. It does not appear to be possible to add the CORS middleware via .proxyrc.js (or at least adding it via app.use() is not effective - it possibly runs too late).

There should be an option that allows the dev server to respond to CORS preflight requests.

🤔 Expected Behaviour

Parcel dev server should work serving assets on a different domain than the application loading the assets, with the Chrome flag chrome://flags/#private-network-access-respect-preflight-results enabled.

😯 Current Behaviour

Preflight requests are ignored by the local dev server.

🔦 Context

In our internal usage, where in development mode assets are served locally, but the application itself is running under a different domain, and with the Chrome flag chrome://flags/#private-network-access-respect-preflight-results enabled, the browser won't load assets from the dev server because the CORS preflight requests are blocked.

💁 Possible Solution

@mischnic
Copy link
Member

mischnic commented Nov 2, 2023

Is there a reason why this has to be a flag for the dev server? Could it just always respond to the preflight requests?

@imbrian
Copy link
Contributor

imbrian commented Nov 2, 2023

It does not appear to be possible to add the CORS middleware via .proxyrc.js (or at least adding it via app.use() is not effective - it possibly runs too late).

Do you have a repro for this? Tried with a fresh Parcel project, and adding the cors middleware to .proxyrc.js seems to be working without changes to the GET/HEAD check in Server.serve. Although, if this is becoming default Chrome behavior, does seem worth supporting out-of-the-box/with a flag.

@marcins
Copy link
Contributor Author

marcins commented Nov 2, 2023

Is there a reason why this has to be a flag for the dev server? Could it just always respond to the preflight requests?

It could - I would assume the default would be fairly relaxed about allowed domains etc, so not sure if folks would want it on by default.. I would assume the risk is low, but I'd prefer to err on the side of caution?

Do you have a repro for this? Tried with a fresh Parcel project, and adding the cors middleware to .proxyrc.js seems to be working without changes to the GET/HEAD check in Server.serve. Although, if this is becoming default Chrome behavior, does seem worth supporting out-of-the-box/with a flag.

I'll ping you internally - it's possible the affected user didn't do this correctly (I didn't check, I took their word for it!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants