Skip to content

Instantly share code, notes, and snippets.

@jonniedarko
Last active August 29, 2015 14:26
Show Gist options
  • Save jonniedarko/f52214bcd31b08b3950f to your computer and use it in GitHub Desktop.
Save jonniedarko/f52214bcd31b08b3950f to your computer and use it in GitHub Desktop.
A very basic reverse proxy server
var http = require('http'),
httpProxy = require('http-proxy'),
proxy = httpProxy.createProxyServer({});
var url = require('url');
http.createServer(function (req, res) {
var pathname = url.parse(req.url).pathname;
console.log('pathname', pathname);
var conversationsPath = '/api/conversations';
var discoverPath = '/api/discover';
if (pathname.substring(0, conversationsPath.length) == conversationsPath) {
console.log(' Conversations >>>> http://localhost:9999');
proxy.web(req, res, {
target: 'http://localhost:9999'
});
}
else if (pathname.substring(0, discoverPath.length) == discoverPath) {
console.log(' Discovery >>>> http://localhost:3330');
proxy.web(req, res, {
target: 'http://localhost:3330'
});
}
else {
console.log(' Norman >>>> http://localhost:9000');
proxy.web(req, res, {
target: 'http://localhost:9000'
});
}
}).listen(8000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment