Categories
JavaScript Answers

How to fix the hostname or IP not matching certificate’s altnames with Node.js?

Spread the love

Sometimes, we want to fix the hostname or IP not matching certificate’s altnames with Node.js.

In this article, we’ll look at how to fix the hostname or IP not matching certificate’s altnames with Node.js.

How to fix the hostname or IP not matching certificate’s altnames with Node.js?

To fix the hostname or IP not matching certificate’s altnames with Node.js, we can use http-proxy with changeOrigin to true.

For instance, we write

const proxy = httpProxy.createProxyServer();

proxy.web(req, res, {
  changeOrigin: true,
  target: 'https://example.com:3000'
});

to create a proxy to proxy the traffic to example.com:3000.

Then we create the server with

httpProxy.createServer({
  ssl: {
    key: fs.readFileSync('valid-ssl-key.pem', 'utf8'),
    cert: fs.readFileSync('valid-ssl-cert.pem', 'utf8')
  },
  target: 'https://example.com:3000',
  secure: true
}).listen(443);

to read the key and certificate with fs.readFileSync and then we set target to the hostname we’re hosting our server from.

Conclusion

To fix the hostname or IP not matching certificate’s altnames with Node.js, we can use http-proxy with changeOrigin to true.

3 replies on “How to fix the hostname or IP not matching certificate’s altnames with Node.js?”

Should I modify or add this lines in the nuxt.config.js ? or create a new file within the nuxt_modules ?

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.