Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

CORS problem origins between React 18 and Symfony 6

I have some problem with CORS between a React web app and a Symfony API with API Platform…

nelmio_cors:
    defaults:
        origin_regex: true
        allow_origin: ['%env(CORS_ALLOW_ORIGIN)%']
        allow_methods: ['GET', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE']
        allow_headers: ['Content-Type', 'Authorization']
        expose_headers: ['Link']
        max_age: 3600
    paths:
        '^/': null
###> nelmio/cors-bundle ###
CORS_ALLOW_ORIGIN='^https?://(localhost|127\.0\.0\.1)(:3000)/?$'
###< nelmio/cors-bundle ###

and this is how I make my request with react :

axios.post(URL + "/login_check", credentials)
        .then(response => response.data)
        .then(data => {
            console.log(data)
        })
        .catch(error => console.log(error))

export const URL = "http://127.0.0.1:8000/api"
I already try to make the wors allow to * and I followed many issues resolution without success…

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I just want to access to my back end without CORS allow problem

Edit : I tried with postman and it works ! but not with my react Application…

>Solution :

CORS_ALLOW_ORIGIN=’^https?://(localhost|127.0.0.1|127.0.0.1:8000)(:3000)?$’

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading