Last active
June 17, 2016 16:53
-
-
Save alfredwesterveld/65792a91234607eb6c1c7a0aaba44d27 to your computer and use it in GitHub Desktop.
tunnel insecure https to http
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
| # Created by .ignore support plugin (hsz.mobi) | |
| ### Node template | |
| # Logs | |
| logs | |
| *.log | |
| npm-debug.log* | |
| # Runtime data | |
| pids | |
| *.pid | |
| *.seed | |
| # Directory for instrumented libs generated by jscoverage/JSCover | |
| lib-cov | |
| # Coverage directory used by tools like istanbul | |
| coverage | |
| # nyc test coverage | |
| .nyc_output | |
| # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | |
| .grunt | |
| # node-waf configuration | |
| .lock-wscript | |
| # Compiled binary addons (http://nodejs.org/api/addons.html) | |
| build/Release | |
| # Dependency directories | |
| node_modules | |
| jspm_packages | |
| # Optional npm cache directory | |
| .npm | |
| # Optional REPL history | |
| .node_repl_history | |
| settings.js | |
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
| 'use strict'; | |
| /* | |
| * Will also work for insecure tunnels (hopefully locally). | |
| */ | |
| const https = require('https') | |
| const httpProxy = require('http-proxy') | |
| const PORT = process.env.PORT || 8888 | |
| function requireSettings() { | |
| return require('./settings.js'); | |
| } | |
| function checkSettings(settings) { | |
| if (!settings.host || !settings.target) { | |
| console.log('copy settings.sample to settings.js and configure'); | |
| process.exit('-1') | |
| } | |
| } | |
| function proxy(settings) { | |
| const proxy = httpProxy.createProxyServer({ | |
| agent : https.globalAgent, | |
| secure: false, // Will also work for insecure https proxies | |
| headers: { | |
| host: settings.host | |
| }, | |
| target: settings.target | |
| }, function(e) { | |
| console.log(e); | |
| }); | |
| proxy.listen(PORT, 'localhost'); | |
| console.log(`listening on port ${PORT}`); | |
| } | |
| const settings = requireSettings(); | |
| checkSettings(settings); | |
| proxy(settings) |
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
| { | |
| "name": "proxy", | |
| "version": "1.0.0", | |
| "description": "", | |
| "main": "index.js", | |
| "scripts": { | |
| "test": "echo \"Error: no test specified\" && exit 1" | |
| }, | |
| "author": "", | |
| "license": "ISC", | |
| "dependencies": { | |
| "http-proxy": "^1.13.3" | |
| } | |
| } |
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
| module.exports = { | |
| target: 'http://localhost:1234', | |
| host: 'localhost' | |
| }; // Port to reverse proxy to. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment