To fix ‘Access-Control-Allow-Origin’ issue when API call made from React isomorphic app, we enable CORS on the back end.
For instance, we write
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
next();
});
to enable CORS in a middleware by sending the Access-Control-Allow-Origin
and Access-Control-Allow-Headers
response headers.