Loading lib/static_handler.js +3 −5 Original line number Diff line number Diff line var url = require('url'); // TODO not needed var path = require('path'); var fs = require('fs'); Loading @@ -7,7 +6,7 @@ var winston = require('winston'); // For serving static assets var StaticHandler = function(path) { this.path = path; this.basePath = path; this.defaultPath = '/index.html'; }; Loading @@ -24,9 +23,8 @@ StaticHandler.contentTypeFor = function(ext) { }; // Handle a request, and serve back the asset if it exists StaticHandler.prototype.handle = function(request, response) { var inc = url.parse(request.url, false); var filePath = this.path + (inc.pathname == '/' ? this.defaultPath : inc.pathname); StaticHandler.prototype.handle = function(incPath, response) { var filePath = this.basePath + (incPath == '/' ? this.defaultPath : incPath); path.exists(filePath, function(exists) { if (exists) { fs.readFile(filePath, function(error, content) { Loading server.js +1 −1 Original line number Diff line number Diff line Loading @@ -35,6 +35,6 @@ http.createServer(function(request, response) { // Otherwise, look for static file handler = new StaticHandler('./static'); handler.handle(request, response); handler.handle(incoming.pathname, response); }).listen(7777); Loading
lib/static_handler.js +3 −5 Original line number Diff line number Diff line var url = require('url'); // TODO not needed var path = require('path'); var fs = require('fs'); Loading @@ -7,7 +6,7 @@ var winston = require('winston'); // For serving static assets var StaticHandler = function(path) { this.path = path; this.basePath = path; this.defaultPath = '/index.html'; }; Loading @@ -24,9 +23,8 @@ StaticHandler.contentTypeFor = function(ext) { }; // Handle a request, and serve back the asset if it exists StaticHandler.prototype.handle = function(request, response) { var inc = url.parse(request.url, false); var filePath = this.path + (inc.pathname == '/' ? this.defaultPath : inc.pathname); StaticHandler.prototype.handle = function(incPath, response) { var filePath = this.basePath + (incPath == '/' ? this.defaultPath : incPath); path.exists(filePath, function(exists) { if (exists) { fs.readFile(filePath, function(error, content) { Loading
server.js +1 −1 Original line number Diff line number Diff line Loading @@ -35,6 +35,6 @@ http.createServer(function(request, response) { // Otherwise, look for static file handler = new StaticHandler('./static'); handler.handle(request, response); handler.handle(incoming.pathname, response); }).listen(7777);