From 4f00d3c71a883b52adcc32cbf87e0a745bdf3992 Mon Sep 17 00:00:00 2001 From: John Crepezzi Date: Fri, 18 Nov 2011 16:00:05 -0500 Subject: [PATCH] Remove url from static_handler.js --- lib/static_handler.js | 8 +++----- server.js | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/static_handler.js b/lib/static_handler.js index bff9969..95b0e57 100644 --- a/lib/static_handler.js +++ b/lib/static_handler.js @@ -1,4 +1,3 @@ -var url = require('url'); // TODO not needed var path = require('path'); var fs = require('fs'); @@ -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'; }; @@ -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) { diff --git a/server.js b/server.js index 9a77610..58f45d2 100644 --- a/server.js +++ b/server.js @@ -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);