'Access to XMLHttpRequest at from origin has been blocked by CORS : The 'Access-Control-Allow-Origin' header contains multiple values '*, *', react

We have deployed our API's on amazon ec2 and we are using these API's on our frontend react.js. We already have set the headers 'Access-Control-Allow-Origin' to '*' in backend

// Preflight API
static setPreflight = async () => {

    const config = {
        headers: {
            'Authorization': `Bearer ${sessionStorage.getItem('authData')}`
        }
    }
    await axios.options(`http://-------/preflight`, config)
}

when we call this function only once to set headers for preflight but we got this error

Access to XMLHttpRequest at 'http://ec2-13-125-149-247--------/preflight' from origin 'http://localhost:3000' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header contains multiple values '*, *', but only one is allowed.

enter image description here

How to resolve this type of error on react.js?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source