From: Darren Date: Tue, 2 Oct 2012 16:31:18 +0000 (+0100) Subject: Serving server defaults via /client/ url X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=b075a0d6c0ad36ae0fb1dc28d789ab6757ae4e0c;p=KiwiIRC.git Serving server defaults via /client/ url --- diff --git a/client_backbone/dev/model_application.js b/client_backbone/dev/model_application.js index b344702..a78c485 100755 --- a/client_backbone/dev/model_application.js +++ b/client_backbone/dev/model_application.js @@ -30,7 +30,7 @@ kiwi.model.Application = Backbone.Model.extend(new (function () { if (!getQueryVariable('debug')) { manageDebug(false); } else { - manageDebug(true); + //manageDebug(true); } // Set the gateway up @@ -106,14 +106,7 @@ kiwi.model.Application = Backbone.Model.extend(new (function () { // Rejigg the UI sizes this.view.doLayout(); - // Populate the server select box with defaults - this.panels.server.server_login.populateFields({ - nick: getQueryVariable('nick') || 'kiwi_' + Math.ceil(Math.random() * 10000).toString(), - server: getQueryVariable('server') || 'irc.kiwiirc.com', - port: 6667, - ssl: false, - channel: window.location.hash || '#test' - }); + this.populateDefaultServerSettings(); }; @@ -122,6 +115,43 @@ kiwi.model.Application = Backbone.Model.extend(new (function () { }; + this.populateDefaultServerSettings = function () { + var parts; + var defaults = { + nick: getQueryVariable('nick') || 'kiwi_' + Math.ceil(Math.random() * 10000).toString(), + server: 'irc.kiwiirc.com', + port: 6667, + ssl: false, + channel: window.location.hash || '#kiwiirc' + }; + + // Process the URL part by part, extracting as we go + parts = window.location.pathname.toString().split('/'); + parts.shift(); + + if (parts.length > 0 && parts[0].toLowerCase() === 'client') { + parts.shift(); + + if (parts.length > 0 && parts[0]) { + console.log(3); + // TODO: Extract the port from this hostname + defaults.server = parts[0]; + parts.shift(); + } + + if (parts.length > 0 && parts[0]) { + defaults.channel = '#' + parts[0]; + parts.shift(); + } + } + + // Set any random numbers if needed + defaults.nick = defaults.nick.replace('?', Math.floor(Math.random() * 100000).toString()); + + // Populate the server select box with defaults + this.panels.server.server_login.populateFields(defaults); + }; + this.bindGatewayCommands = function (gw) { gw.on('onmotd', function (event) { diff --git a/client_backbone/index.html b/client_backbone/index.html index b3cd01e..dc244a6 100755 --- a/client_backbone/index.html +++ b/client_backbone/index.html @@ -2,6 +2,7 @@ + KiwiIRC diff --git a/server/http-handler.js b/server/http-handler.js index 9beeba4..0393565 100755 --- a/server/http-handler.js +++ b/server/http-handler.js @@ -13,6 +13,11 @@ var StaticFileServer = function (public_html) { }; StaticFileServer.prototype.serve = function (request, response) { + // Any requests for /client to load the index file + if (request.url.match(/^\/client/)) { + request.url = '/'; + } + this.fileServer.serve(request, response, function (err) { if (err) { response.writeHead(err.status, err.headers);