From 4fc23261b3d1bf9ce4a2ba7e81bff1141fc032ef Mon Sep 17 00:00:00 2001 From: Michelle Bu Date: Sat, 1 Mar 2014 12:28:23 -0800 Subject: [PATCH] Add option --- lib/server.js | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/server.js b/lib/server.js index 6d820a9..1679e92 100644 --- a/lib/server.js +++ b/lib/server.js @@ -15,7 +15,8 @@ function PeerServer(options) { key: 'peerjs', ip_limit: 5000, concurrent_limit: 5000, - ssl: {} + ssl: {}, + path: '/' }, options); util.debug = this._options.debug; @@ -27,6 +28,14 @@ function PeerServer(options) { } this._options.ssl['name'] = 'PeerServer'; + + if (this._options.path[0] !== '/') { + this._options.path = '/' + this._options.path; + } + if (this._options.path[this._options.path.length - 1] !== '/') { + this._options.path += '/'; + } + this._app = restify.createServer(this._options.ssl); // Connected clients @@ -56,7 +65,7 @@ PeerServer.prototype._initializeWSS = function() { var self = this; // Create WebSocket server as well. - this._wss = new WebSocketServer({ path: '/peerjs', server: this._app}); + this._wss = new WebSocketServer({ path: this._options.path + 'peerjs', server: this._app}); this._wss.on('connection', function(socket) { var query = url.parse(socket.upgradeReq.url, true).query; @@ -180,14 +189,14 @@ PeerServer.prototype._initializeHTTP = function() { this._app.use(util.allowCrossDomain); // Retrieve guaranteed random ID. - this._app.get('/:key/id', function(req, res, next) { + this._app.get(this._options.path + ':key/id', function(req, res, next) { res.contentType = 'text/html'; res.send(self._generateClientId(req.params.key)); return next(); }); // Server sets up HTTP streaming when you get post an ID. - this._app.post('/:key/:id/:token/id', function(req, res, next) { + this._app.post(this._options.path + ':key/:id/:token/id', function(req, res, next) { var id = req.params.id; var token = req.params.token; var key = req.params.key; @@ -241,13 +250,13 @@ PeerServer.prototype._initializeHTTP = function() { return next(); }; - this._app.post('/:key/:id/:token/offer', handle); + this._app.post(this._options.path + ':key/:id/:token/offer', handle); - this._app.post('/:key/:id/:token/candidate', handle); + this._app.post(this._options.path + ':key/:id/:token/candidate', handle); - this._app.post('/:key/:id/:token/answer', handle); + this._app.post(this._options.path + ':key/:id/:token/answer', handle); - this._app.post('/:key/:id/:token/leave', handle); + this._app.post(this._options.path + ':key/:id/:token/leave', handle); // Listen on user-specified port. this._app.listen(this._options.port);