fix crashbug caused by using semicolons instead of commas and/or lack of require...
[KiwiIRC.git] / server / http-handler.js
1 var url = require('url'),
2 node_static = require ('node-static');
3
4 var HTTPHandler = function (config) {
5 this.static_file_server = new StaticFileServer(config.public_html);
6 };
7
8 module.exports.HTTPHandler = HTTPHandler;
9
10 var StaticFileServer = function (public_html) {
11 public_html = public_html || 'client_backbone/';
12 this.fileServer = new node_static.Server(public_html);
13 };
14
15 StaticFileServer.prototype.serve = function (request, response) {
16 this.fileServer.serve(request, response, function (err) {
17 if (err) {
18 response.writeHead(err.status, err.headers);
19 response.end();
20 }
21 });
22 };
23
24 HTTPHandler.prototype.handler = function (request, response) {
25 var uri, subs;
26
27 uri = url.parse(request.url, true);
28 subs = uri.pathname.substr(0, 4);
29
30 if (uri.pathname.substr(0, 10) === '/socket.io') {
31 return;
32 } else {
33 this.static_file_server.serve(request, response);
34 }
35 };