-
-
Save jakelly/31c9f908eddb07275dc3de8117bf5b41 to your computer and use it in GitHub Desktop.
Demonstrate setting up an Express proxy server proxying to SSL site
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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