nelmio / NelmioCorsBundle

Adds CORS (Cross-Origin Resource Sharing) headers support in your Symfony application
https://symfony.com/bundles/NelmioCorsBundle/
MIT License
1.89k stars 108 forks source link

NelmioCorsBundle not setting ALLOW_ORIGINS (Heroku Server) #170

Closed dariusmann closed 1 year ago

dariusmann commented 3 years ago

I am have a API Backend (Symfony) and a SPA Frontend (Vue) running on two different Heroku Apps.

Backend: https://igrat-backend.herokuapp.com Frontend: https://igrat-frontend.herokuapp.com

In my Symfony App I use the NelmioCorsBundle to enable CORS.

Here is my NelmioCorsBundle config file:

nelmio_cors:
    defaults:
        allow_credentials: true
        origin_regex: true
        allow_origin: ['*']
        allow_methods: ['GET', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE']
        allow_headers: ['Content-Type','Authorization']
        expose_headers: ['Link']
        max_age: 3600
    paths:
        '^/': ~

Nevertheless the Access-Control-Allow-Origin header is not being set and I get the following error making a request from my Frontend to my Backend: Bildschirmfoto 2021-10-14 um 23 10 58

To reproduce go to https://igrat-frontend.herokuapp.com, click on Login in the menu and type in any credentials to fire the request.

Extra information:

web: vendor/bin/heroku-php-apache2 public/

lazka commented 3 years ago

not sure if this is the problem, but origin_regex is set to true, but allow_origin isn't a valid regex

huynguyen93 commented 2 years ago

I had the same problem, no error logs occurred or anything, but I found out there was code for debugging that used dump().

Change your environment to dev and see the in the profiler if you have anything in tab Debug.

In prod environment, dump() will not work (but I don't know why there was no errors logged).

I removed it and the headers were back.