From 903f92880cd0c26f39b87306a7ceb29259fbed1e Mon Sep 17 00:00:00 2001 From: Darren Date: Wed, 4 Jun 2014 16:18:17 +0100 Subject: [PATCH] Simplified http handler. /deep/base/path/urls/irc.network.com URLs now working --- client/build.js | 2 +- client/src/models/application.js | 2 +- server/httphandler.js | 23 ++++++++++------------- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/client/build.js b/client/build.js index 01ea6c4..e7c4b2e 100644 --- a/client/build.js +++ b/client/build.js @@ -221,7 +221,7 @@ fs.readdir(__dirname + '/src/translations', function (err, translation_files) { */ var index_src = fs.readFileSync(__dirname + '/src/index.html.tmpl', FILE_ENCODING) - .replace(new RegExp('<%base_path%>', 'g'), config.get().http_base_path || '/kiwi') + .replace(new RegExp('<%base_path%>', 'g'), config.get().http_base_path || '') .replace(new RegExp('<%build_version%>', 'g'), package_json.version); fs.writeFile(__dirname + '/index.html', index_src, { encoding: FILE_ENCODING }, function (err) { diff --git a/client/src/models/application.js b/client/src/models/application.js index 43af0b4..4b828f2 100644 --- a/client/src/models/application.js +++ b/client/src/models/application.js @@ -16,7 +16,7 @@ } // The base url to the kiwi server - this.set('base_path', options.base_path ? options.base_path : '/kiwi'); + this.set('base_path', options.base_path ? options.base_path : ''); // Path for the settings.json file this.set('settings_path', options.settings_path ? diff --git a/server/httphandler.js b/server/httphandler.js index f491dde..477992b 100644 --- a/server/httphandler.js +++ b/server/httphandler.js @@ -20,25 +20,22 @@ module.exports.HttpHandler = HttpHandler; HttpHandler.prototype.serve = function (request, response) { // The incoming requests base path (ie. /kiwiclient) - var base_path = global.config.http_base_path || '/kiwi', - base_path_regex; + var base_path = global.config.http_base_path || '', + whitelisted_folders = ['assets', 'src']; - // Trim of any trailing slashes + // Trim off 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(base_path + '/assets/', '/assets/'); - - // Any src request to head into the src dir - request.url = request.url.replace(base_path + '/src/', '/src/'); + // Map any whitelisted folders to the local directories + whitelisted_folders.forEach(function(folder) { + request.url = request.url.replace(base_path + '/' + folder + '/', '/' + folder + '/'); + }); - // Any requests for /client to load the index file - if (request.url.match(new RegExp('^' + base_path_regex + '([/$]|$)', 'i'))) { + // Any requests for /base_path/* to load the index file + console.log(request.url, base_path); + if (request.url.toLowerCase().indexOf(base_path.toLowerCase()) === 0) { request.url = '/index.html'; } -- 2.25.1