Last active
December 11, 2015 01:39
-
-
Save theon/4525329 to your computer and use it in GitHub Desktop.
This file contains 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 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