From b65ad8f1a05df41c7cdf288e1fb25a91041c77f0 Mon Sep 17 00:00:00 2001 From: Darren Date: Mon, 22 Oct 2012 14:59:15 +0100 Subject: [PATCH] HttpHandler reading from config. Default client subdir changed to /kiwi. #96 --- server/config.js | 3 +++ server/httphandler.js | 22 +++++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/server/config.js b/server/config.js index 7a8ec27..534e5b1 100644 --- a/server/config.js +++ b/server/config.js @@ -70,6 +70,9 @@ conf.transports = [ "jsonp-polling" ]; +// Base HTTP path to the KIWI IRC client (eg. /kiwi) +conf.http_base_path = "/kiwi"; + // Default quit message conf.quit_message = "http://www.kiwiirc.com/ - A hand-crafted IRC client"; diff --git a/server/httphandler.js b/server/httphandler.js index 950f1e5..7c982c9 100644 --- a/server/httphandler.js +++ b/server/httphandler.js @@ -1,5 +1,6 @@ var url = require('url'), - node_static = require ('node-static'); + node_static = require ('node-static'), + config = require('./configuration.js'); @@ -13,16 +14,23 @@ module.exports.HttpHandler = HttpHandler; HttpHandler.prototype.serve = function (request, response) { - // The incoming requests root directory (ie. /kiwiclient/) - // TODO: check the config for this setting - var root_path = '/client', - root_path_regex = root_path.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&'); + // The incoming requests base path (ie. /kiwiclient) + var base_path = config.get().http_base_path || '/kiwi', + base_path_regex; + + // Trim of any trailing slashes + if (base_path.substr(base_path.length - 1) === '/') { + base_path = base_path.substr(0, base_path.length - 1); + } + + // Build the regex to match the base_path + base_path_regex = base_path.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&'); // Any asset request to head into the asset dir - request.url = request.url.replace(root_path + '/assets/', '/assets/'); + request.url = request.url.replace(base_path + '/assets/', '/assets/'); // Any requests for /client to load the index file - if (request.url.match(new RegExp('^' + root_path_regex, 'i'))) { + if (request.url.match(new RegExp('^' + base_path_regex + '([/$]|$)', 'i'))) { request.url = '/'; } -- 2.25.1