Changeset View
Changeset View
Standalone View
Standalone View
support/aphlict/server/lib/AphlictClientServer.js
| Show First 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | members: { | ||||
| _onrequest: function(request, response) { | _onrequest: function(request, response) { | ||||
| // The websocket code upgrades connections before they get here, so | // The websocket code upgrades connections before they get here, so | ||||
| // this only handles normal HTTP connections. We just fail them with | // this only handles normal HTTP connections. We just fail them with | ||||
| // a 501 response. | // a 501 response. | ||||
| response.writeHead(501); | response.writeHead(501); | ||||
| response.end('HTTP/501 Use Websockets\n'); | response.end('HTTP/501 Use Websockets\n'); | ||||
| }, | }, | ||||
| _parseInstanceFromPath: function(path) { | |||||
| // If there's no "~" marker in the path, it's not an instance name. | |||||
| // Users sometimes configure nginx or Apache to proxy based on the | |||||
| // path. | |||||
| if (path.indexOf('~') === -1) { | |||||
| return 'default'; | |||||
| } | |||||
| var instance = path.split('~')[1]; | |||||
| // Remove any "/" characters. | |||||
| instance = instance.replace(/\//g, ''); | |||||
| if (!instance.length) { | |||||
| return 'default'; | |||||
| } | |||||
| return instance; | |||||
| }, | |||||
| listen: function() { | listen: function() { | ||||
| var self = this; | var self = this; | ||||
| var server = this._server.listen.apply(this._server, arguments); | var server = this._server.listen.apply(this._server, arguments); | ||||
| var wss = new WebSocket.Server({server: server}); | var wss = new WebSocket.Server({server: server}); | ||||
| wss.on('connection', function(ws) { | wss.on('connection', function(ws) { | ||||
| var instance = url.parse(ws.upgradeReq.url).pathname; | var path = url.parse(ws.upgradeReq.url).pathname; | ||||
| var instance = self._parseInstanceFromPath(path); | |||||
| instance = instance.replace(/\//g, ''); | |||||
| if (!instance.length) { | |||||
| instance = 'default'; | |||||
| } | |||||
| var listener = self.getListenerList(instance).addListener(ws); | var listener = self.getListenerList(instance).addListener(ws); | ||||
| function log() { | function log() { | ||||
| self.log( | self.log( | ||||
| util.format('<%s>', listener.getDescription()) + | util.format('<%s>', listener.getDescription()) + | ||||
| ' ' + | ' ' + | ||||
| util.format.apply(null, arguments)); | util.format.apply(null, arguments)); | ||||
| ▲ Show 20 Lines • Show All 47 Lines • Show Last 20 Lines | |||||