1
0
Fork 0
mirror of https://github.com/SunRed/haste-server.git synced 2024-11-27 11:20:18 +01:00

Remove url from static_handler.js

This commit is contained in:
John Crepezzi 2011-11-18 16:00:05 -05:00
parent 44d54174ed
commit 4f00d3c71a
2 changed files with 4 additions and 6 deletions

View file

@ -1,4 +1,3 @@
var url = require('url'); // TODO not needed
var path = require('path'); var path = require('path');
var fs = require('fs'); var fs = require('fs');
@ -7,7 +6,7 @@ var winston = require('winston');
// For serving static assets // For serving static assets
var StaticHandler = function(path) { var StaticHandler = function(path) {
this.path = path; this.basePath = path;
this.defaultPath = '/index.html'; this.defaultPath = '/index.html';
}; };
@ -24,9 +23,8 @@ StaticHandler.contentTypeFor = function(ext) {
}; };
// Handle a request, and serve back the asset if it exists // Handle a request, and serve back the asset if it exists
StaticHandler.prototype.handle = function(request, response) { StaticHandler.prototype.handle = function(incPath, response) {
var inc = url.parse(request.url, false); var filePath = this.basePath + (incPath == '/' ? this.defaultPath : incPath);
var filePath = this.path + (inc.pathname == '/' ? this.defaultPath : inc.pathname);
path.exists(filePath, function(exists) { path.exists(filePath, function(exists) {
if (exists) { if (exists) {
fs.readFile(filePath, function(error, content) { fs.readFile(filePath, function(error, content) {

View file

@ -35,6 +35,6 @@ http.createServer(function(request, response) {
// Otherwise, look for static file // Otherwise, look for static file
handler = new StaticHandler('./static'); handler = new StaticHandler('./static');
handler.handle(request, response); handler.handle(incoming.pathname, response);
}).listen(7777); }).listen(7777);