It searched and already included the typical backend code
app.use(function (req, res, next) {
//res.setHeader('Access-Control-Allow-Origin', 'http://localhost:3000/storeScore');
res.header('Access-Control-Allow-Origin', '*');
//res.header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
next();
});
but I still get Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:3000/storeScore. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). followed by
Uncaught (in promise) TypeError: NetworkError when attempting to fetch resource. I mean don't I have the header res.header('Access-Control-Allow-Origin', '*'); ?
My frontend code is
function someFunction() {
const sessionHighscore = cumulativeScore;
const options = {
method: 'POST',
headers: {
//'Origin' : 'http://localhost:80',
'Content-Type': 'application/json'
},
body: JSON.stringify(sessionHighscore)
};
fetch('http://localhost:3000/storeScore', options);
}
Maybe I need to include something in client-side header? I think local html is hosted on port 80?
Notes:
Edit: