Http-server: https certificate error when proxying to server with self-signed certificate

Created on 2 Dec 2015  路  3Comments  路  Source: http-party/http-server

In development we often deal with dev. servers which have self-signed SSL certificate. If I use --proxy option pointing to such a server - I get following error upon proxy attempt:

node_modules/http-proxy/lib/http-proxy/index.js:119
    throw err;
          ^
Error: SELF_SIGNED_CERT_IN_CHAIN
    at SecurePair.<anonymous> (tls.js:1381:32)
    at SecurePair.emit (events.js:92:17)
    at SecurePair.maybeInitFinished (tls.js:980:10)
    at CleartextStream.read [as _read] (tls.js:472:13)
    at CleartextStream.Readable.read (_stream_readable.js:341:10)
    at EncryptedStream.write [as _write] (tls.js:369:25)
    at doWrite (_stream_writable.js:226:10)
    at writeOrBuffer (_stream_writable.js:216:5)
    at EncryptedStream.Writable.write (_stream_writable.js:183:11)
    at write (_stream_readable.js:602:24)

This will not happen if you pass secure: false option to httpProxy.createProxyServer. You can do it by default or enable with some option. I can compose a pull request if you like.

Most helpful comment

In my mac I did the following hack (Because I have no time to make a PR)

  1. Install npm install -g http-server
  2. Edited the global http-server.js located in (my mac) /usr/local/lib/node_modules/http-server/lib/http-server.js. I installed node via homebrew
  3. At line 105 add the secure: false option like this: var proxy = httpProxy.createProxyServer({secure: false});
  4. Submit a PR with this change (optional)

Caveats: This is a developer's solution to a developer's problem. You should not make this change in a production environment or something like that. I personally would set this as a cli config parameter.

All 3 comments

This is sooooo needed fix - especially if I'm using this for proxying in development where I have multiple backends and all of them with self signed cert.
What will be good is to have support for more then proxy backend - same as proxyPass directive in Apache.

Any news on this ?

In my mac I did the following hack (Because I have no time to make a PR)

  1. Install npm install -g http-server
  2. Edited the global http-server.js located in (my mac) /usr/local/lib/node_modules/http-server/lib/http-server.js. I installed node via homebrew
  3. At line 105 add the secure: false option like this: var proxy = httpProxy.createProxyServer({secure: false});
  4. Submit a PR with this change (optional)

Caveats: This is a developer's solution to a developer's problem. You should not make this change in a production environment or something like that. I personally would set this as a cli config parameter.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jiyinyiyong picture jiyinyiyong  路  6Comments

frank-dspeed picture frank-dspeed  路  7Comments

Altiano picture Altiano  路  7Comments

arthurkhlghatyan picture arthurkhlghatyan  路  3Comments

jondlm picture jondlm  路  6Comments