Buscó y ya incluyó el típico código backend
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(); }); pero sigo teniendo una 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). seguido por
Uncaught (in promise) TypeError: NetworkError when attempting to fetch resource. Quiero decir, ¿no tengo el encabezado res.header('Access-Control-Allow-Origin', '*'); ?
Mi código de interfaz es
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); }¿Tal vez necesito incluir algo en el encabezado del lado del cliente? ¿Creo que el html local está alojado en el puerto 80?
Notas:
Editar: