I've tried just about every suggestion out there to solve a CORS issue (47 different ways to be exact). I'm beginning to think the issue is not on CORS side but in how my axios request is set up. My question is simple: Is it possible my issue is with my axios setup and not with my server side CORS set up?
Error: Blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Frontend React
useEffect(async () => {
const result = await axios({
method: "GET",
withCredentials: true,
url: "site-backend.herokuapp.com",
}).then((res) => {
setMasterUserAccount(res.data.username);
});
}, []);
Backend Express/Node: CORS
const cors = require("cors");
var corsOptions = {
methods: ["GET", "POST", "DELETE", "UPDATE", "PUT", "PATCH"],
origin: "https://site.herokuapp.com",
optionSuccessStatus: 200,
credentials: true,
};
app.use(cors(corsOptions));
Here's the response from the network tab:
Request URL: https://site-backend.herokuapp.com/userData
Request Method: GET
Status Code: 503
Referrer Policy: strict-origin-when-cross-origin
Cache-Control: no-cache, no-store
Connection: keep-alive
Content-Length: 506
Content-Type: text/html; charset=utf-8
Date: Wed, 31 Aug 2022 16:54:44 GMT
Server: Cowboy
Accept: application/json, text/plain,
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Connection: keep-alive
Host: site-backend.herokuapp.com
Origin: https://site.herokuapp.com
Referer: https://site.herokuapp.com/
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: cross-site