Permalink
Browse files

static folder use application __dirname

  • Loading branch information...
1 parent 047d244 commit cf5d124a24eff97b03b1dbd477a8c617c27939d2 @alberto-bottarini committed Aug 16, 2012
Showing with 6 additions and 2 deletions.
  1. +5 −1 httpdispatcher.js
  2. +1 −1 package.json
View
@@ -7,6 +7,7 @@ var HttpDispatcher = function() {
res.end();
}
this.staticFolderPrefix = '/static';
+ this.staticDirname;
}
HttpDispatcher.prototype.on = function(method, url, cb) {
this.listeners[method].push({
@@ -32,6 +33,9 @@ HttpDispatcher.prototype.onError = function(cb) {
HttpDispatcher.prototype.setStatic = function(folder) {
this.on('get', new RegExp("\/"+folder), this.staticListener.bind(this));
}
+HttpDispatcher.prototype.setStaticDirname = function(dirname) {
+ this.staticDirname = dirname;
+}
HttpDispatcher.prototype.beforeFilter = function(url, cb) {
this.filter('before', url, cb);
}
@@ -72,7 +76,7 @@ HttpDispatcher.prototype.dispatch = function(req, res) {
}
HttpDispatcher.prototype.staticListener = function(req, res) {
var url = require('url').parse(req.url, true);
- var filename = require('path').join(".", url.pathname);
+ var filename = require('path').join(this.staticDirname, url.pathname);
var errorListener = this.errorListener;
require('fs').readFile(filename, function(err, file) {
if(err) {
View
@@ -13,5 +13,5 @@
"main": "httpdispatcher.js",
"name": "httpdispatcher",
"repository": {"url": "https://github.com/alberto-bottarini/httpdispatcher", "type": "git"},
- "version": "0.3.0"
+ "version": "0.4.0"
}

0 comments on commit cf5d124

Please sign in to comment.