initial commit
[map.git] / honeymap-master / proxy / proxy.js
1 var http = require('http'), httpProxy = require('http-proxy');
2
3 var backend_nginx = new httpProxy.HttpProxy({ target: { host: 'localhost', port: 81 } });
4 var backend_socketio = new httpProxy.HttpProxy({ target: { host: 'localhost', port: 82 }});
5
6 // Redirect socket.io requests to socket.io and static content to nginx
7 var server = http.createServer(function(req, res) {
8   if(req.url.match(/^\/socket\.io\//)) {
9     backend_socketio.proxyRequest(req, res);
10   } else {      
11     backend_nginx.proxyRequest(req, res);
12   }
13 });
14
15 // Redirect websocket requests to the socket.io server
16 server.on('upgrade', function(req, socket, head) {
17   backend_socketio.proxyWebSocketRequest(req, socket, head);
18 });
19
20 server.listen(80);
21
22 // Drop privileges
23 process.setuid(1000);