CORS problem origins between React 18 and Symfony 6

326 Views Asked by At

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...

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...

0

There are 0 best solutions below