Reputation: 453
I am using Node.js and node-fetch to retrieve JSON. This code has been working for over a year, I have not touched the code in a long time, and recently it stopped working.
Here is my fetch code:
let response = await fetch('https://[mydomain]/api.php', {method: 'POST', headers: headers, body: body});
const data = await response.json();
I did not include the body and header objects, but they are defined a few lines above my fetch. Like I mentioned, this was all working until a few days ago.
Here is the error I am receiving:
rejected promise not handled within 1 second: FetchError: request to https://[mydomain]/api.php?reset failed, reason: certificate has expired
/Applications/Visual Studio Code.app/Contents/Resources/app/out/bootstrap-fork.js:5
stack trace: FetchError: request to https://[mydomain]/api.php?reset failed, reason: certificate has expired
The domain has a valid certificate. I've manually checked it and used a few different tools to check it. I'm using Open SSL and I renewed the SSL just in case.
The Node.js is running inside a VS Code extension, but I don't think that is related.
Any idea why Node.js thinks the SSL is expired? Or is there a way I could have fetch ignore this warning? The extension is pri,arily for my personal use and API is on my own personal server.
Upvotes: 3
Views: 8464
Reputation: 642
Try adding process.env.NODE_TLS_REJECT_UNAUTHORIZED='0'
to the file where you are initializing the request.
Upvotes: 2