I'm doing a project in React.js where I have to get API's datas and I got the
No
Access-Control-Allow-Origin
header is present on the requested resource. Origin 'null' is therefore not allowed access.
problem
Even with this in the server.js
:
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const cors = require('cors');
const port = process.env.PORT || 5000;
app.use(cors())
app.use(function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Credentials', true);
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With,
Content-Type, Accept');
res.header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT,
DELETE');
next();
});
app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.json())
app.listen(port, () => console.log(`Listening on port ${port}`));
Can someone help me because I saw like 20 topics about this, and I did all the solutions given in the commentaries.
Thank you !
edit : if this can help, the status code of the request is 304