Michelle Bu vor 11 Jahren
Ursprung
Commit
4fc23261b3
1 geänderte Dateien mit 17 neuen und 8 gelöschten Zeilen
  1. 17 8
      lib/server.js

+ 17 - 8
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);