Skip to content

Instantly share code, notes, and snippets.

@theon
Last active December 11, 2015 01:39
Show Gist options
  • Save theon/4525329 to your computer and use it in GitHub Desktop.
Save theon/4525329 to your computer and use it in GitHub Desktop.
var http = require('http'),
httpProxy = require('http-proxy');
//
// A node http-proxy application to sit in front of a cube server (https://github.com/square/cube)
// and do some primitive authentication to require a password (specified in the 'cube-password' header
// in order call the write apis, but still allowing anyone to call the read apis.
//
httpProxy.createServer(function (req, res, proxy) {
if(req.method !== 'OPTIONS' && req.method !== 'GET') {
if(req.headers['cube-password'] !== 'change_this_password') {
res.writeHead(403);
res.end();
return;
}
proxy.proxyRequest(req, res, {
host: 'localhost',
port: 1080
});
} else {
proxy.proxyRequest(req, res, {
host: 'localhost',
port: 1081
});
}
}).listen(80);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment