Node-http-proxy: Example of proxying to a server with TLS client authentication

Created on 10 Nov 2016  路  2Comments  路  Source: http-party/node-http-proxy

Hi,

I have use case where I'm proxying to a server w/ require mutal tls? If so is there any documentation of that?

Regards,
Dat

Most helpful comment

After digging through the code I finally got POC that worked, hopefully this can help someone else.

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

var options = {
  pfx: fs.readFileSync('clientCert.pfx'),
  passphrase: 'password',
  rejectUnauthorized: false
};
options.agent = new https.Agent(options);

var proxyConfig = {
  target: 'https://localhost:8080/',
  agent: options.agent
};

proxyConfig = Object.assign(proxyConfig,options);

var proxy = httpProxy.createProxyServer(proxyConfig);


var server = http.createServer(function(req, res) {
  proxy.web(req, res);
});

server.listen(5050);


All 2 comments

After digging through the code I finally got POC that worked, hopefully this can help someone else.

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

var options = {
  pfx: fs.readFileSync('clientCert.pfx'),
  passphrase: 'password',
  rejectUnauthorized: false
};
options.agent = new https.Agent(options);

var proxyConfig = {
  target: 'https://localhost:8080/',
  agent: options.agent
};

proxyConfig = Object.assign(proxyConfig,options);

var proxy = httpProxy.createProxyServer(proxyConfig);


var server = http.createServer(function(req, res) {
  proxy.web(req, res);
});

server.listen(5050);


Hi there! Your snippet helped me in finding a solution to a similar problem.

I also made a Pull Request #1209, adding an example to the official use cases in order to help other people in the future.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

karthikus picture karthikus  路  3Comments

miton18 picture miton18  路  5Comments

robertjchristian picture robertjchristian  路  6Comments

martindale picture martindale  路  6Comments

jnjnljljjsw picture jnjnljljjsw  路  6Comments