Routing HTTP to HTTPS with invalid certificate would work with process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
It gives an error:
[HPM] Error occurred while trying to proxy request /service1/api/BasicOrder/OrderId/17072037 from localhost:8083 to http://localhost:8000 (UNABLE_TO_VERIFY_LEAF_SIGNATURE) (https://nodejs.org/api/errors.html#errors_common_system_errors)
See below
Complete code follows:
const fs = require('fs');
const express = require('express');
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
const proxy = require('http-proxy-middleware');
const config = JSON.parse(fs.readFileSync('config.json', 'utf8'));
const { routes } = config;
const router = (req) => {
const source = req.url;
const target = routes.find(r => source.startsWith(r.from));
return target && target.to;
};
const routingProxy = proxy({
target: 'http://localhost:8000',
router
});
const app = express();
app.use(routingProxy);
app.listen(8083);
{
"routes": [
{ "from": "/service1", "to": "https://services-dev-01:10000" }
]
}
The solution was to add secure: false on the proxy configuration.
Most helpful comment
The solution was to add
secure: falseon the proxy configuration.