Description
I'm trying to create a proxy to an https server that is setup for client certificate authentication. I'm passing the certificate and the key to the proxy via the ssl object, but the connection is not being established. Here's my code:
var pcert = fs.readFileSync('./client_cert.pem');
var pkey = fs.readFileSync('./private_key.pem');
proxy = httpProxy.createProxyServer({
target: 'https://my.backend.server',
json: true,
ssl: {
key: pkey,
cert: pcert
}
}.listen(8000);
The following code (written by someone else) creates a stand-alone server that passes client requests to the same backend server, with the same certificate/key, and it's working:
http.createServer(onRequest).listen(3030);
function onRequest(client_req, client_res) {
var pcert = fs.readFileSync('./portal_client_cert.pem');
var pkey = fs.readFileSync('./private_key.pem');
var options = {
key: pkey,
cert: pcert,
agent: false,
host: 'my.backend.server',
method: client_req.method,
path: client_req.url,
json: true,
headers:{
Host: 'my.backend.server'
}
};
var proxy = https.get(options, function(res) {
res.pipe(client_res, {
end: true
});
}
I'd like to create a proxy server instead of a standalone server, so that I could pass it to the Gulp server we're using. I tried passing the cert and the key as part of the target object instead, but that doesn't work either:
target: {
host: 'my.backend.server',
port: 443,
protocol: 'https:',
key: pkey,
cert: pcert,
}
What am I missing?