-
Notifications
You must be signed in to change notification settings - Fork 109
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
Environment variable in configuration set to * #99
Comments
Can confirm, stumbled across the same problem. I had to directly edit the yaml file to get it working. I should have checked here before wasting my time searching!
In the
|
I have the same problem. |
@nataliaAznar Could you please share your .yaml with us? I'm still stuck with that issue and I can't figure it out. |
Yes, of course. I have solved it just ignoring de CORS_ALLOW_ORIGIN of the .env file, an writting it directly in the yaml: nelmio_cors:
defaults:
origin_regex: true
allow_origin: ['*']
allow_methods: ['GET', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE']
allow_headers: ['*']
max_age: 3600
paths:
'^/': ~ |
Thank you @nataliaAznar !
I tried to set: nelmio_cors:
defaults:
allow_credentials: true
origin_regex: true
# allow_origin: ['%env(CORS_ALLOW_ORIGIN)%']
allow_origin: ['https://FRONT-URL.com']
allow_methods: ['GET', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE']
allow_headers: ['Content-Type', 'Authorization']
max_age: 3600
paths:
'^/': ~ But I still got that wildcard '*' error. |
Have you try without the "allow_credentials: true" ? |
Yes, but no better luck. |
Interesting to note here: ...
if ($options['allow_origin'] === true) return true;
if ($options['origin_regex'] === true) {
// origin regex matching
foreach($options['allow_origin'] as $originRegexp) {
if (preg_match('{'.$originRegexp.'}i', $origin)) {
return true;
}
}
} else {
... The regex provides the desired Uncaught PHP Exception ErrorException: "Warning: preg_match(): Compilation failed: nothing to repeat at offset 0" at /var/task/vendor/nelmio/cors-bundle/EventListener/CorsListener.php line 193 In conclusion, either
|
Great bundle, but please add this limitation in the doc, I get mad trying to compile |
Dot( nelmio_cors:
defaults:
allow_origin: ['%env(CORS_ALLOW_ORIGIN)%']
origin_regex: true
|
I think it should be at least CORS_ALLOW_ORIGIN=.* |
In the current form XHR requests are only allowed from localhost - for whatever reason. In order to use the cover service from clientside applications on other domains we need to open up for other domains. This should open up for all domains. I originally wanted to set the value to * but there seems to be problems with this approach when using the Nelmio bundle: nelmio/NelmioCorsBundle#99. According to the comments . should work.
This is still not solved. I'm using Symfony 5.1.7 and .env
nelmio_cors.yaml
But still getting an error: |
? quelqu'un a trouvez une solution à cette problématique? |
Four years on and this is still an issue. I assume it's due to a limitation in Symfony and the way environment variables are loaded. Allowing The only solution we've come up with so far is to hard code the value into different parameter files (local, staging and production) rather than configuring once and using and environment variable. Anyone got any other solutions which actually achieve the goal of setting via environment variables? |
As far as I can tell this was solved by 2.0.0 in 2c46344 - if anyone still has this issue with the latest version please open a new issue with more details. @alexbaileyuk I believe your issue is more #148 |
Hi,
I am using environment variable to set the
allow_origin
setting. But it is not working when I set the env var to * (CORS_ALLOW_ORIGIN=*
)Here is my nelmio_cors.yaml
After an hour of debugging I found out when you are processing configuration in the
NelmioCorsExtension
you are over writing['*']
withtrue
which is then used byCorsListener::checkOrigin
. Unfortunately the env vars are not process by the timeNelmioCorsExtension::load
is fired which results in$defaults
configuration to be:So this mean the
allow_origin
is not being over written withtrue
, which results inCorsListener::checkOrigin
not working as expected. Is there any other way we could setallow_origin
to be a*
with env var?I am using:
The text was updated successfully, but these errors were encountered: