Http-proxy-middleware: Routing to HTTPS with invalid certificate

Created on 7 Jan 2018  路  1Comment  路  Source: chimurai/http-proxy-middleware

Expected behavior

Routing HTTP to HTTPS with invalid certificate would work with process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';

Actual behavior

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)

Setup

  • http-proxy-middleware: 0.17.14
  • server: express 4.16.2

proxy middleware configuration

See below

server mounting

Complete code follows:

server.js
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);
config.json
{
  "routes": [
    { "from": "/service1", "to": "https://services-dev-01:10000" }
  ]
}

Most helpful comment

The solution was to add secure: false on the proxy configuration.

>All comments

The solution was to add secure: false on the proxy configuration.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zh-h picture zh-h  路  3Comments

ghostd picture ghostd  路  7Comments

pwlerke picture pwlerke  路  6Comments

joshiste picture joshiste  路  4Comments

DylanPiercey picture DylanPiercey  路  6Comments