Node built in fetch dont reject unauthorized - How to handle self-signed certificates? or Why does no

20 Replies, 1736 Views

Yeah, the node built in fetch dont reject unauthorized certs by default, which is wild.

For enforcing strict checks, you can use the `https` agent with `rejectUnauthorized: true`. Here's a quick snippet:

```javascript
import https from 'https';
const agent = new https.Agent({ rejectUnauthorized: true });
fetch('https://yoursite.com', { agent });
```

If you're using something like Axios, it’s similar—just pass the agent in the config.

Also, check out the `node-fetch` docs if you’re using an older version. They’ve got some quirks too.

Messages In This Thread



Users browsing this thread: 1 Guest(s)