0

I am currently trying to connect my web client to its back-end architecture. Everything is set as it should and everything seems to be working correctly, except that I have got the following error:

CORS POLICY ERROR

I am currently building this client with react and the connection to the backend has been made with the following model:

model.js (of the Orchestrator // back-end connection)


// Model of the orchestrator based on the backend itself

export const stateNamespace = 'orchestrator';

export const initialState = {
    connectionParameters: {
        protocol: process.env.REACT_APP_ORCHESTRATOR_PROTOCOL || 'https',
        hostname: process.env.REACT_APP_ORCHESTRATOR_HOSTNAME || 'localhost',
        port: parseInt(process.env.REACT_APP_ORCHESTRATOR_PORT) || 8443,
    },
}

export function reducer (localState, action){
    switch (action.type){
        default:
    }
}

and here is the .env file linked to it:


REACT_APP_ORCHESTRATOR_PROTOCOL = https
REACT_APP_ORCHESTRATOR_HOSTNAME = localhost
REACT_APP_ORCHESTRATOR_PORT = 8443

Is there anything that I could do to fix this? I have spoken to some people and they said that most probably I would need to serve the CORS headers in the react dev server, however I have no clue how to do so. Or is it a back-end side issue and I cannot do anything?

iLuca
  • 1
  • 3
  • @EnfieldLi not really, in on of the responses the person suggested to add the CORS headers, how can I do it and most importantly where should I do it? This isn't specified and it really isn't clear... – iLuca Mar 17 '23 at 09:17
  • You need to understand what does the CORS error mean. You will need changes on your backend server https://stackoverflow.com/a/49814950/4379903 to allow your host: `https://localhost:8443` – Abhishek Ghosh Mar 17 '23 at 09:21
  • @AbhishekGhosh unfortunately I do not have access to the backend at the moment, any clues on how I would be able to add the CORS headers on the front end? – iLuca Mar 17 '23 at 09:34
  • You cannot handle CORS on the frontend. Please read this: https://auth0.com/blog/cors-tutorial-a-guide-to-cross-origin-resource-sharing/ – Abhishek Ghosh Mar 17 '23 at 09:42

0 Answers0