Skip to content

Instantly share code, notes, and snippets.

@jakelly
Last active March 2, 2018 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakelly/31c9f908eddb07275dc3de8117bf5b41 to your computer and use it in GitHub Desktop.
Save jakelly/31c9f908eddb07275dc3de8117bf5b41 to your computer and use it in GitHub Desktop.
Demonstrate setting up an Express proxy server proxying to SSL site
const express = require('express');
const https = require('https');
const httpProxy = require('http-proxy');
const app = express();
// Omitted Code...
// Establish SSL Cert Info
// These files were generated using openSSL.
const ssl = {
key: fs.readFileSync('./ssl/example.com.key', 'utf8'),
cert: fs.readFileSync('./ssl/example.com.crt', 'utf8')
};
// Omitted Code...
const proxy = httpProxy.createProxyServer({
// The agent attribute is necessary to reach backend server
agent: new httpsProxyAgent('http://corporateproxy.example.com'),
headers: {
host: 'example.com'
},
secure: true,
// The ssl attribute is necessary if the backend server is SSL encrypted
ssl: ssl,
// The target attribute defines the backend server we are reaching
target: 'https://example.com'
});
app.all('*', (req, res) => proxy.web(req, res));
https.createServer(ssl, app).listen(process.env.listenPort);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment