Created
June 20, 2011 04:49
-
-
Save clifton/1035143 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
fe1 localhost:3000 | |
fe2 127.0.0.1:3000 | |
fe3 0.0.0.0:3000 |
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
live1 0.0.0.0:8082 |
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
node1 0.0.0.0:8100 |
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
http = require 'http' | |
{HttpProxy} = require 'http-proxy' | |
proxy = new HttpProxy | |
{HostList} = require './lib/host-list' | |
backends = {} | |
server = http.createServer (req, res) -> | |
target = backends[route req].get() | |
proxy.proxyRequest req, res, target | |
server.on 'upgrade', (req, socket, head) -> | |
target = backends[route req].get() | |
proxy.proxyWebSocketRequest req, socket, head, target | |
server.listen 8000 | |
route = (req) -> | |
_route = req.url.match /^\/([\w]+)/ | |
if req.upgrade | |
'live' | |
else if _route and backends[_route[1]]? | |
_route[1] | |
else | |
'frontends' | |
for group in ['live', 'frontends', 'node'] | |
backends[group] = new HostList group |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment