Node-http-proxy: from http to https proxy method?

Created on 28 Sep 2016  路  2Comments  路  Source: http-party/node-http-proxy

Sample Code

var http = require('http'),
    httpProxy = require('http-proxy');

//
// Create a proxy server with latency
//
var proxy = httpProxy.createProxyServer();

//
// Create your server that makes an operation that waits a while
// and then proxies the request
//
http.createServer(function (req, res) {
  // This simulates an operation that takes 500ms to execute
  setTimeout(function () {
    proxy.web(req, res, {
      target: 'https://www.google.co.kr'
    });
  }, 500);
}).listen(8008);

Error Stack

Error: Hostname/IP doesn't match certificate's altnames: "IP: xxx.xxx.xxx.xxx is not in the cert's list: "
at Object.checkServerIdentity (tls.js:203:15)
at TLSSocket. (_tls_wrap.js:1061:29)
at emitNone (events.js:86:13)
at TLSSocket.emit (events.js:185:7)
at TLSSocket._finishInit (_tls_wrap.js:580:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:412:38)

Most helpful comment

try adding the changeOrigin: true

http.createServer(function (req, res) {
  setTimeout(function () {
    proxy.web(req, res, {
      target: 'https://www.google.co.kr',
      changeOrigin: true
    });
  }, 500);
}).listen(8008);

All 2 comments

try adding the changeOrigin: true

http.createServer(function (req, res) {
  setTimeout(function () {
    proxy.web(req, res, {
      target: 'https://www.google.co.kr',
      changeOrigin: true
    });
  }, 500);
}).listen(8008);

Thanks! It was helpful. I tested by your advice. and it was succeeded.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jnjnljljjsw picture jnjnljljjsw  路  6Comments

robertjchristian picture robertjchristian  路  6Comments

lgzhang picture lgzhang  路  4Comments

miton18 picture miton18  路  5Comments

karthikus picture karthikus  路  3Comments