Edit: I don't ask anything about cors here
So I have spent hours trying to figure out what's goin on, and well ... I'm losing it...
So I have this simple app that has the server part made in nodejs and the front end in react, they run on diferent ports so I used cors module.
Anyway So this is my nodejs api using express
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cors());
app.get('/', (req, res) => {
res.send({data:"Hello"});
});
app.listen(port, () => console.log(`Listening on port ${port}`));
and then from react the following fetch request
fetch("http://www.localhost:5000/",{
method: 'GET',
mode: "no-cors",
cache: "no-cache",
credentials: "same-origin",
headers: {"Content-Type": "application/json"}
})
.then(res=>{
console.log("res1",res)
res.text();
})
.then(res=>{
console.log("res2",res)
})
.catch(res=>{
console.log("Exception : ",res);
})
The thing is this req returns undefined whatever I try. In res 1 the response is an object ( in this case opaque )
Response {type: "opaque", url: "", redirected: false, status: 0, ok: false, …}
And well res2 is undefined.
What am I missing ?