I have a simple .NET Core WebAPI
with no authentication. I added Cors with default policy. I have no problem connecting and fetching data from my React website or Postman (everything runs locally on my machine). Now I'm trying to fetch data from that API in super simple node
application and I'm getting this error:
file:///Users/aw/Projects/TestNodeApp/node_modules/node-fetch/src/index.js:94
reject(new FetchError(`request to ${request.url} failed, reason: ${error.message}`, 'system', error));
^
FetchError: request to https://localhost:5001/api/teams failed, reason: self signed certificate
at ClientRequest.<anonymous> (file:///Users/aw/Projects/TestNodeApp/node_modules/node-fetch/src/index.js:94:11)
at ClientRequest.emit (node:events:394:28)
at TLSSocket.socketErrorListener (node:_http_client:447:9)
at TLSSocket.emit (node:events:394:28)
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
type: 'system',
errno: 'DEPTH_ZERO_SELF_SIGNED_CERT',
code: 'DEPTH_ZERO_SELF_SIGNED_CERT',
erroredSysCall: undefined
}
This is my whole node
application:
import fetch from 'node-fetch';
async function fetchTeams() {
const response = await fetch('https://localhost:5001/api/teams', { method: 'GET' });
const data = await response.json();
return data;
}
(async () => {
console.log('Process started');
const teams = await fetchTeams();
console.log(teams);
})().finally(() => {
console.log('Process finished');
});
What does it mean? What Am I missing?
Btw. It works fine, when I'm fetching Github API, like this:
async function fetchGithub() {
const response = await fetch('https://api.github.com/users/Microsoft');
const data = await response.json();
return data;
}
So I assume, something is missing in the API. Something that my React website doesn't need, that node app needs.
Thanks for help!