From d8d472fb03a4ab5d104af445444ac666ce054fe1 Mon Sep 17 00:00:00 2001 From: Vasil Dininski Date: Thu, 20 Mar 2014 16:02:33 +0200 Subject: [PATCH] Fixed a race condition in the debug-server.js Now setting the port number as a query string. If no port number is provided the default port will be used. --- front-end-node/Overrides.js | 1 + lib/debug-server.js | 17 ++++++++--------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/front-end-node/Overrides.js b/front-end-node/Overrides.js index 49fb895..2696e2e 100644 --- a/front-end-node/Overrides.js +++ b/front-end-node/Overrides.js @@ -9,6 +9,7 @@ WebInspector.loaded = function() { var a = document.createElement('a'); // browser will resolve this relative path to an absolute one a.href = 'ws'; + a.search = window.location.search; a.protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'; return a.href; }(); diff --git a/lib/debug-server.js b/lib/debug-server.js index 32430bc..cd23dff 100644 --- a/lib/debug-server.js +++ b/lib/debug-server.js @@ -10,8 +10,6 @@ var http = require('http'), WEBROOT = path.join(__dirname, '../front-end'); function debugAction(req, res) { - var config = this._config; - config.debugPort = getDebuggerPort(req.url, config.debugPort); res.sendfile(path.join(WEBROOT, 'inspector.html')); } @@ -19,12 +17,9 @@ function overridesAction(req, res) { res.sendfile(path.join(__dirname, '../front-end-node/Overrides.js')); } -function getDebuggerPort(url, defaultPort) { - return parseInt((/\?port=(\d+)/.exec(url) || [null, defaultPort])[1], 10); -} - function handleWebSocketConnection(socket) { - this._createSession().join(socket); + var debugPort = this._getDebuggerPort(socket.upgradeReq.url); + this._createSession(debugPort).join(socket); } function handleServerListening() { @@ -63,8 +58,12 @@ DebugServer.prototype.start = function(options) { httpServer.listen(this._config.webPort, this._config.webHost); }; -DebugServer.prototype._createSession = function() { - return Session.create(this._config.debugPort, this._config); +DebugServer.prototype._getDebuggerPort = function(url) { + return parseInt((/\?port=(\d+)/.exec(url) || [null, this._config.debugPort])[1], 10); +}; + +DebugServer.prototype._createSession = function(debugPort) { + return Session.create(debugPort, this._config); }; DebugServer.prototype.close = function() {