I am trying to run a MERN application in the workspace. I have both the frontend and backend in the same workspace. My NodeJS server is running in port 4000 where as my React application is running in port 5173
and the mapped urls for both of them are as follows:
Backend: 5173-idx-workwave-1716606407475.cluster-bs35cdu5w5cuaxdfch3hqqt7zm.cloudworkstations.dev
Frontend: 4000-idx-workwave-1716606407475.cluster-bs35cdu5w5cuaxdfch3hqqt7zm.cloudworkstations.dev
when trying to access the backend from the browser directly it does hit the server but when trying to hit the server using the frontend it responds with
Access to XMLHttpRequest at ‘backendurl’) from origin ‘frontendurl’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
and I have tried the steps from the docs as well
and have ran the following bash command
export port=4000
Can you check my post about the same issue and confirm if you have the same result: Cors Issue?
I think your application has an Authorization token sent to its backend, is this correct? Also, your calls should include the withCredentials parameter (depending on what library you are using).
I am getting the same issue , above solution works for GET Method , but not working for POST method getting “preflight invalid allow credentials” cors error. Do you find any solution for this?
Simply configure cors on your server to accept requests from diff origins,
origins other than 3000 and 5173 will not be processed.
on prod you have to change them as per your FE urls
app.use(cors({
origin: ['http://localhost:5173', 'http://localhost:3000'], // Allowed origins
credentials: true, // Allow cookies or headers like Authorization
}));
this will allow your frontend to communicate with backend.