Created
August 30, 2014 10:15
-
-
Save tristola/7e1e85087c0d4d15e708 to your computer and use it in GitHub Desktop.
Node.js simple proxy
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'); | |
var proxy = httpProxy.createProxyServer({}); | |
var server = require('http').createServer(function(req, res) { | |
if(req.url.indexOf('/rest')==0){ | |
try{ | |
proxy.web(req, res, { target: 'http://127.0.0.1:8888'+req.url }); | |
}catch(err){ | |
} | |
} else { | |
proxy.web(req, res, { target: 'http://127.0.0.1:3000'}); | |
} | |
}); | |
server.listen(5050); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment