Last active
October 20, 2015 22:15
-
-
Save ismaels/9960771 to your computer and use it in GitHub Desktop.
Creates a http proxy server used as a router for two app instances running on different ports
This file contains hidden or 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'); | |
// Create a proxy server with custom application logic | |
var proxy = httpProxy.createProxyServer({}); | |
// | |
// Create your custom server and just call `proxy.web()` to proxy | |
// a web request to the target passed in the options | |
// also you can use `proxy.ws()` to proxy a websockets request | |
// | |
var server = require('http').createServer(function(req, res) { | |
// You can define here your custom logic to handle the request | |
// and then proxy the request. | |
if(req.url.match(/api\/appointments\/v1/) !== null){ | |
proxy.web(req, res, { target: 'http://127.0.0.1:3001' }); | |
}else{ | |
proxy.web(req, res, { target: 'http://127.0.0.1:3002' }); | |
} | |
}); | |
console.log("listening on port 3000") | |
server.listen(3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment