Created
June 29, 2016 19:41
-
-
Save nemtsov/482c4f826ad3dd4b43a4dc3d267aaf23 to your computer and use it in GitHub Desktop.
Simple HTTPS proxy server
This file contains hidden or 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
| var https = require('https'); | |
| var fs = require('fs'); | |
| var url = require('url'); | |
| process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; | |
| var options = { | |
| key: fs.readFileSync(process.env.HOME + '/.ssh/self_signed_key.pem'), | |
| cert: fs.readFileSync(process.env.HOME + '/.ssh/self_signed_cert.pem'), | |
| }; | |
| var server = https.createServer(options, function(req, res) { | |
| var urlPath = url.parse(req.url).path; | |
| https.get(process.env.PROXY_TO + urlPath, function(gres) { | |
| res.setHeader('Content-Type', gres.headers['content-type']); | |
| res.statusCode = gres.statusCode; | |
| gres.pipe(res); | |
| }); | |
| }); | |
| server.listen(3000, function() { | |
| console.log('on :3000'); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: generate your certs with:
Set the COMMON NAME to your domain name. Don't add the protocol or port.
Start the server with: