8000 Feature Request - Web Server CORS? · Issue #229 · symfony-cli/symfony-cli · GitHub
[go: up one dir, main page]

Skip to content

Feature Request - Web Server CORS? #229

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

Closed
svbackend opened this issue Nov 23, 2022 · 5 comments
Closed

Feature Request - Web Server CORS? #229

svbackend opened this issue Nov 23, 2022 · 5 comments

Comments

@svbackend
Copy link

Hello, currently I'm using symfony serve command for local development which starts web server for symfony app binded to 127.0.0.1:8000 (and other random port) but whenever I'm making request from react app which is on 127.0.0.1:3000 I'm getting CORS error.

I know that there are bundles to fix this issue but the reason I don't want to install them is that I don't really need CORS on production and don't really want to add additional logic like if APP_ENV == dev { add cors headers } it's just for local development, so I thought maybe the ideal place to handle this issue is actually symfony web server itself since it's used specifically for local development?

Additional option like symfony serve --disable-cors would be perfect solution, or you guys think it's not the right place to handle it?

@tucksaun
Copy link
Member
tucksaun commented Dec 6, 2022

Hello @svbackend,

As a workaround, maybe you can only register and enable the bundle in dev so that you don't need the additional logic ?

Features request-wise, lately I have seen quite a lot of this use, so maybe the Symfony CLI should answer this use case.
The problem I see trying to implement this with just a flag or a similar option is that CORS have many options and features so this is not easy to implement except if we only add a flag that whitelists any cross-origin request (and displays a big warning header).
Symfony CLI being only development-oriented this might be "okay" and we could redirect users to https://github.com/nelmio/NelmioCorsBundle if they need more fine-grained control.

Another alternative would be to allow somehow proxying the JS dev server so that both contents are served from the same origin. I didn't put any though into this kind of UX or implementation so I have no clue how to do this.

@tucksaun
Copy link
Member

I stumbled on the need for CORS today as well.
Event though the project I'm working on uses NelmioCorsBundle in the proper way, the JS app was using static assets served by the application. But because those assets are static and served by the CLI, the Symfony app can not add the right headers.
In my case serving the JS app from the same domain is not possible so the second solution I was mentioning would not have helped either.

This is another proof that CORS configuration could be useful.

@fabpot what do you thin 8000 k about adding a -enable-cors or -allow-cors flag?
With a warning at the start of the server to mention one should consider NelmioCorsBundle and the application headers taking precedence ofc.

@fabpot
Copy link
Contributor
fabpot commented Feb 15, 2023

That would work for me.

@Kocal
Copy link
Contributor
Kocal commented Mar 15, 2023

Hi, I've opened a PR at #293

@binarious
Copy link

What about the idea of allowing the addition of custom headers in .symfony.local.yaml? This would m 8000 ake it easier to set things like CSP, HSTS, etc. without the need for another dev dependency.

Kocal added a commit to Kocal/symfony-cli that referenced this issue Sep 18, 2024
Kocal added a commit to Kocal/symfony-cli that referenced this issue Oct 10, 2024
Kocal added a commit to Kocal/symfony-cli that referenced this issue Dec 5, 2024
@fabpot fabpot closed this as completed in 577e097 Dec 9, 2024
fabpot added a commit that referenced this issue Dec 9, 2024
feat(http): add flag/config to allow CORS requests, close #229
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

5 participants
0