1 var url
= require('url'),
2 node_static
= require ('node-static');
6 var HttpHandler = function (config
) {
7 var public_html
= config
.public_html
|| 'client/';
8 this.file_server
= new node_static
.Server(public_html
);
11 module
.exports
.HttpHandler
= HttpHandler
;
15 HttpHandler
.prototype.serve = function (request
, response
) {
16 // The incoming requests root directory (ie. /kiwiclient/)
17 // TODO: check the config for this setting
18 var root_path
= '/client',
19 root_path_regex
= root_path
.replace(/[-/\\^$*+?.()|[\]{}]/g
, '\\$&');
21 // Any asset request to head into the asset dir
22 request
.url
= request
.url
.replace(root_path
+ '/assets/', '/assets/');
24 // Any requests for /client to load the index file
25 if (request
.url
.match(new RegExp('^' + root_path_regex
, 'i'))) {
30 this.file_server
.serve(request
, response
, function (err
) {
32 response
.writeHead(err
.status
, err
.headers
);