Skip to content

Instantly share code, notes, and snippets.

@FvD
Forked from trestletech/.gitignore
Created July 7, 2014 17:21
Show Gist options
  • Save FvD/ba6a546814435dc2ce8a to your computer and use it in GitHub Desktop.
Save FvD/ba6a546814435dc2ce8a to your computer and use it in GitHub Desktop.
var _ = require('underscore');
var http = require('http');
var httpProxy = require('http-proxy');
var https = require('https');
var fs = require('fs');
var opts = require('optimist')
.usage('Test auth proxy.\nUsage: $0 [extPort] [destPort] [destHostName] --ssl')
.describe('ssl', 'Enable SSL on both the client and expect it on the target.')
.demand(0);
var argv = opts.argv;
var port = argv._[0]?argv._[0] : 8000;
var destPort = argv._[1]?argv._[1] : 3838;
var destHostname = (argv._[2])?argv._[2] : 'localhost';
var options = {
target: {
https: argv.ssl,
rejectUnauthorized: false
}
}
if (argv.ssl){
options.https = {
key: fs.readFileSync('/home/jeff/workspace/test-key.pem'),
cert: fs.readFileSync('/home/jeff/workspace/test-cert.pem')
}
}
var proxy = new httpProxy.HttpProxy({
target: {
host: destHostname,
port: destPort,
https: argv.ssl,
rejectUnauthorized: false
}
});
if (argv.ssl){
https.createServer(options.https, function (req, res) {
req.headers['SOME_AUTH'] = 'SOMETHING';
proxy.proxyRequest(req, res);
}).listen(port);
} else{
http.createServer(function (req, res) {
req.headers['SOME_AUTH'] = 'SOMETHING';
proxy.proxyRequest(req, res);
}).listen(port);
}
{
"name": "test-auth-proxy",
"preferGlobal": "false",
"version": "0.1.0",
"author": "RStudio <jeff@rstudio.com>",
"description": "Simple auth proxy.",
"bin": "./main.js",
"scripts": {
"start": "node ./main.js 8000 3838 localhost"
},
"repository": {
"type": "git",
"url": "https:///gist.github.com/7160493"
},
"dependencies" : {
"http-proxy" : "0.10.x",
"underscore" : "1.4.x",
"optimist" : "0.6.x"
},
"license": "AGPL-3",
"engines": {
"node": ">=0.8.16"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment