Loading lib/static_handler.js +18 −17 Original line number Diff line number Diff line Loading @@ -8,6 +8,12 @@ var winston = require('winston'); var StaticHandler = function(path) { this.basePath = path; this.defaultPath = '/index.html'; // Grab the list of available files - and move into hash for quick lookup var available = fs.readdirSync(this.basePath); this.availablePaths = {}; for (var i = 0; i < available.length; i++) { this.availablePaths['/' + available[i]] = true; } }; // Determine the content type for a given extension Loading @@ -24,10 +30,11 @@ StaticHandler.contentTypeFor = function(ext) { // Handle a request, and serve back the asset if it exists StaticHandler.prototype.handle = function(incPath, response) { // Go to index if not found or / if (!this.availablePaths[incPath]) incPath = this.defaultPath; var filePath = this.basePath + (incPath == '/' ? this.defaultPath : incPath); // And then stream the file back var _this = this; path.exists(filePath, function(exists) { if (exists) { fs.readFile(filePath, function(error, content) { if (error) { winston.error('unable to read file', { path: filePath, error: error.message }); Loading @@ -40,12 +47,6 @@ StaticHandler.prototype.handle = function(incPath, response) { response.end(content, 'utf-8'); } }); } else { // serve the default route so that pushstate can work if not found _this.handle('/', response); } }); }; module.exports = StaticHandler; server.js +0 −1 Original line number Diff line number Diff line Loading @@ -26,7 +26,6 @@ if (config.logging) { } } // TODO preparse static instead of using exists // TODO implement command line // Set the server up Loading Loading
lib/static_handler.js +18 −17 Original line number Diff line number Diff line Loading @@ -8,6 +8,12 @@ var winston = require('winston'); var StaticHandler = function(path) { this.basePath = path; this.defaultPath = '/index.html'; // Grab the list of available files - and move into hash for quick lookup var available = fs.readdirSync(this.basePath); this.availablePaths = {}; for (var i = 0; i < available.length; i++) { this.availablePaths['/' + available[i]] = true; } }; // Determine the content type for a given extension Loading @@ -24,10 +30,11 @@ StaticHandler.contentTypeFor = function(ext) { // Handle a request, and serve back the asset if it exists StaticHandler.prototype.handle = function(incPath, response) { // Go to index if not found or / if (!this.availablePaths[incPath]) incPath = this.defaultPath; var filePath = this.basePath + (incPath == '/' ? this.defaultPath : incPath); // And then stream the file back var _this = this; path.exists(filePath, function(exists) { if (exists) { fs.readFile(filePath, function(error, content) { if (error) { winston.error('unable to read file', { path: filePath, error: error.message }); Loading @@ -40,12 +47,6 @@ StaticHandler.prototype.handle = function(incPath, response) { response.end(content, 'utf-8'); } }); } else { // serve the default route so that pushstate can work if not found _this.handle('/', response); } }); }; module.exports = StaticHandler;
server.js +0 −1 Original line number Diff line number Diff line Loading @@ -26,7 +26,6 @@ if (config.logging) { } } // TODO preparse static instead of using exists // TODO implement command line // Set the server up Loading