[Pkg-javascript-commits] [node-static] 106/151: One single Server exports.

Tonnerre Lombard tonnerre-guest at moszumanska.debian.org
Tue Jan 7 23:18:01 UTC 2014


This is an automated email from the git hooks/post-receive script.

tonnerre-guest pushed a commit to branch master
in repository node-static.

commit a78aaba9ba32385626ea3b5748b6026fc66fd592
Author: David Sargeant <david at dsargeant.com>
Date:   Mon Apr 1 09:30:44 2013 -0400

    One single Server exports.
---
 lib/node-static.js | 39 ++++++++++++++++-----------------------
 1 file changed, 16 insertions(+), 23 deletions(-)

diff --git a/lib/node-static.js b/lib/node-static.js
index fde1f0e..e06f6fe 100644
--- a/lib/node-static.js
+++ b/lib/node-static.js
@@ -5,7 +5,7 @@ var fs     = require('fs')
   , url    = require('url')
   , path   = require('path');
 
-exports.version = [0, 6, 5];
+exports.version = [0, 6, 7];
 
 var mime = require('./node-static/mime');
 var util = require('./node-static/util');
@@ -15,7 +15,7 @@ exports.store = {};
 exports.indexStore = {};
 exports.mime = mime;
 
-exports.Server = function (root, options) {
+Server = function (root, options) {
     if (root && (typeof(root) === 'object')) { options = root; root = null }
 
     this.root    = path.resolve(root || '.');
@@ -24,7 +24,7 @@ exports.Server = function (root, options) {
 
     this.defaultHeaders  = {};
     this.options.headers = this.options.headers || {};
-
+    
     if ('cache' in this.options) {
         if (typeof(this.options.cache) === 'number') {
             this.cache = this.options.cache;
@@ -44,14 +44,14 @@ exports.Server = function (root, options) {
     if (this.cache !== false) {
         this.defaultHeaders['cache-control'] = 'max-age=' + this.cache;
     }
-
+    
     for (var k in this.defaultHeaders) {
         this.options.headers[k] = this.options.headers[k] ||
                                   this.defaultHeaders[k];
     }
 };
 
-exports.Server.prototype.serveDir = function (pathname, req, res, finish) {
+Server.prototype.serveDir = function (pathname, req, res, finish) {
     var htmlIndex = path.join(pathname, 'index.html'),
         that = this;
 
@@ -80,10 +80,10 @@ exports.Server.prototype.serveDir = function (pathname, req, res, finish) {
     }
 };
 
-exports.Server.prototype.serveFile = function (pathname, status, headers, req, res) {
+Server.prototype.serveFile = function (pathname, status, headers, req, res) {
     var that = this;
     var promise = new(events.EventEmitter);
-
+    
     pathname = this.resolve(pathname);
 
     fs.stat(pathname, function (e, stat) {
@@ -97,7 +97,7 @@ exports.Server.prototype.serveFile = function (pathname, status, headers, req, r
     return promise;
 };
 
-exports.Server.prototype.finish = function (status, headers, req, res, promise, callback) {
+Server.prototype.finish = function (status, headers, req, res, promise, callback) {
     var result = {
         status:  status,
         headers: headers,
@@ -130,7 +130,7 @@ exports.Server.prototype.finish = function (status, headers, req, res, promise,
     }
 };
 
-exports.Server.prototype.servePath = function (pathname, status, headers, req, res, finish) {
+Server.prototype.servePath = function (pathname, status, headers, req, res, finish) {
     var that = this,
         promise = new(events.EventEmitter);
 
@@ -163,28 +163,20 @@ exports.Server.prototype.servePath = function (pathname, status, headers, req, r
     return promise;
 };
 
-exports.Server.prototype.resolve = function (pathname) {
+Server.prototype.resolve = function (pathname) {
     return path.resolve(path.join(this.root, pathname));
 };
 
-exports.Server.prototype.serve = function (req, res, callback) {
+Server.prototype.serve = function (req, res, callback) {
     var that = this,
         promise = new(events.EventEmitter);
+    
+    var pathname = decodeURI(url.parse(req.url).pathname);
 
     var finish = function (status, headers) {
         that.finish(status, headers, req, res, promise, callback);
     };
 
-    var pathname;
-    try {
-        pathname = decodeURI(url.parse(req.url).pathname);
-    }
-    catch(e) {
-        return process.nextTick(function() {
-            return finish(400, {});
-        });
-    }
-
     process.nextTick(function () {
         that.servePath(pathname, 200, {}, req, res, finish).on('success', function (result) {
             promise.emit('success', result);
@@ -195,7 +187,7 @@ exports.Server.prototype.serve = function (req, res, callback) {
     if (! callback) { return promise }
 };
 
-exports.Server.prototype.respond = function (pathname, status, _headers, files, stat, req, res, finish) {
+Server.prototype.respond = function (pathname, status, _headers, files, stat, req, res, finish) {
     var mtime   = Date.parse(stat.mtime),
         key     = pathname || files[0],
         headers = {},
@@ -251,7 +243,7 @@ exports.Server.prototype.respond = function (pathname, status, _headers, files,
     }
 };
 
-exports.Server.prototype.stream = function (pathname, files, buffer, res, callback) {
+Server.prototype.stream = function (pathname, files, buffer, res, callback) {
     (function streamFile(files, offset) {
         var file = files.shift();
 
@@ -278,3 +270,4 @@ exports.Server.prototype.stream = function (pathname, files, buffer, res, callba
     })(files.slice(0), 0);
 };
 
+exports.Server = Server;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-static.git



More information about the Pkg-javascript-commits mailing list