Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,25 @@ app.use('/', proxy('httpbin.org', {
}));
```

#### optionalCertAuthority

This is a certificate object or array of certificate objects (just like what you'd pass to the https agent for a normal request). Use this to connect to hosts with https that use internal or known, self-signed certificates.

```js
var caCert = fs.readFileSync('certs/root-cert.crt');
var intermediaryCert = fs.readFileSync('certs/intermediary-cert.crt');

app.use('/', proxy('internalhost.example.com', {
optionalCertAuthority: {
[caCert, intermediaryCert]
}
}));

```





## Questions

Expand Down
9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ module.exports = function proxy(host, options) {
prepareRequest.then(function(results) {
var path = results[0];
var bodyContent = results[1];
sendProxyRequest(req, res, next, path, bodyContent);
sendProxyRequest(req, res, next, path, bodyContent, options.optionalCertAuthority);
});
};


function sendProxyRequest(req, res, next, path, bodyContent) {
function sendProxyRequest(req, res, next, path, bodyContent, optionalCertAuthority) {
parsedHost = parsedHost || parseHost(host, req, options);


var reqOpt = {
hostname: parsedHost.host,
port: options.port || parsedHost.port,
Expand All @@ -51,6 +52,10 @@ module.exports = function proxy(host, options) {
params: req.params,
};

if (optionalCertAuthority) {
reqOpt.ca = optionalCertAuthority;
}

if (preserveReqSession) {
reqOpt.session = req.session;
}
Expand Down