To fix Node.js Hostname/IP doesn’t match certificate’s altnames, we proxy to the target URL.
For instance, we write
const proxy = httpProxy.createProxyServer();
proxy.web(req, res, {
changeOrigin: true,
target: "https://example.com:3000",
});
to call proxy.web to proxy requests to https://example.com:3000.
If we use HTTPS, we should include the key and certificate by writing
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 call add call createServer with the key and cert set.
And we proxy requests to https://example.com:3000.