2

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.

Adam
  • 125
  • 1
  • 12
  • How did you check the certificate on your server? It may just be a coincidence, but yesterday was the expiration date for zillions of free certificates from Let's Encrypt (you need to get a fresh certificate). I would suggest checking again for server certificate expiration. – jfriend00 Oct 05 '21 at 18:42
  • I just used a few different SSL checkers, like this one: https://www.sslshopper.com/ssl-checker.html – Adam Oct 05 '21 at 20:41
  • Well, since you don't say what your actual domain is, there's not much else we can do to help you diagnose things. It seems fairly clear that "something" has expired, somewhere. I wouldn't be searching for ways to work-around the warning. You really ought to understand why it says what it says and fix the issue. One thing to check is the clocks on your server and client to make sure no dates are way off. – jfriend00 Oct 06 '21 at 00:11
  • What node and node-fetch versions are you using? We've had a similar issue with one of our applications that popped up a few days ago. We were using an old node version and updating to a more recent version solved it. – Sebastian Richner Oct 08 '21 at 13:58

1 Answers1

1

Try adding process.env.NODE_TLS_REJECT_UNAUTHORIZED='0' to the file where you are initializing the request.

Y H
  • 492
  • 5
  • 9
  • 1
    I added this and I get lots of warnings about making "HTTPS requests insecure" but it is now working again! Thanks! – Adam Oct 05 '21 at 22:00
  • 3
    Don't actually use this in production. See this rather old SO question: https://stackoverflow.com/questions/20433287/node-js-request-cert-has-expired Ignore the accepted answer and read the one with the most upvotes by user coolaj86. – Sebastian Richner Oct 08 '21 at 13:59