Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix bug in static handler

  • Loading branch information...
commit 87a0c27a6812488c06d756700fce8193da392ba4 1 parent c1f266e
@Shogun147 authored
Showing with 23 additions and 21 deletions.
  1. +23 −21 lib/static.js
View
44 lib/static.js
@@ -1,27 +1,29 @@
-var server = new (require('node-static').Server)('./');
+var Path = require('path');
-var config = App.Config();
+var server = new (require('node-static').Server)('./');
+var options = App.Config().static;
-if (config.static.error_log === undefined) {
- config.static.error_log = false;
-}
+options.error_log = options.error_log || false;
App.on('connection', function(request, response, callback) {
- if (request.url == '/favicon.ico') {
- request.url = '/'+ config.static.path + 'favicon.ico';
+ var url = Path.resolve(decodeURI(request.url));
+
+ if (url === '/favicon.ico') {
+ url = '/'+ options.path + 'favicon.ico';
}
-
- if (config.static.enabled && request.url.indexOf('/'+ config.static.path)===0) {
- server.serve(request, response, function(error, resp) {
- if (error) {
- error.url = request.url;
-
- config.static.error_log && console.log(error);
- }
- });
-
- return callback(true);
+
+ if (!options.enabled || url.indexOf('/'+ options.path)!==0) {
+ return callback();
}
-
- callback();
-});
+
+ request.url = url;
+
+ server.serve(request, response, function(error, res) {
+ if (error) {
+ response.writeHead(error.status, error.headers);
+ response.end(error.message);
+ }
+
+ callback(true);
+ });
+});
Please sign in to comment.
Something went wrong with that request. Please try again.