Skip to content

Instantly share code, notes, and snippets.

@alfredwesterveld
Last active June 17, 2016 16:53
Show Gist options
  • Select an option

  • Save alfredwesterveld/65792a91234607eb6c1c7a0aaba44d27 to your computer and use it in GitHub Desktop.

Select an option

Save alfredwesterveld/65792a91234607eb6c1c7a0aaba44d27 to your computer and use it in GitHub Desktop.
tunnel insecure https to http
# 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
'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)
{
"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"
}
}
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