[Pkg-javascript-commits] [node-serve-static] 01/06: Imported Upstream version 1.2.3

Leo Iannacone l3on-guest at moszumanska.debian.org
Mon Jun 16 20:19:24 UTC 2014


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

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

commit 317e83ca686dac4d31b17b069fc857c2167e46cb
Author: Leo Iannacone <l3on at ubuntu.com>
Date:   Mon Jun 16 21:52:34 2014 +0200

    Imported Upstream version 1.2.3
---
 .gitignore   |  65 -----------------------------------
 .npmignore   |   4 ++-
 .travis.yml  |   6 ++++
 History.md   |  35 +++++++++++++++++++
 Readme.md    |  65 ++++++++++++++++++++++++++++++-----
 index.js     |  21 ++----------
 package.json |  25 ++++++--------
 test/test.js | 109 +++++++++++------------------------------------------------
 8 files changed, 135 insertions(+), 195 deletions(-)

diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index c4cdf95..0000000
--- a/.gitignore
+++ /dev/null
@@ -1,65 +0,0 @@
-# Compiled source #
-###################
-*.com
-*.class
-*.dll
-*.exe
-*.o
-*.so
-
-# Packages #
-############
-# it's better to unpack these files and commit the raw source
-# git has its own built in compression methods
-*.7z
-*.dmg
-*.gz
-*.iso
-*.jar
-*.rar
-*.tar
-*.zip
-
-# Logs and databases #
-######################
-*.log
-*.sql
-*.sqlite
-
-# OS generated files #
-######################
-.DS_Store*
-ehthumbs.db
-Thumbs.db
-
-# Node.js #
-###########
-lib-cov
-*.seed
-*.log
-*.csv
-*.dat
-*.out
-*.pid
-*.gz
-
-pids
-logs
-results
-
-node_modules
-npm-debug.log
-
-# Git #
-#######
-*.orig
-*.BASE.*
-*.BACKUP.*
-*.LOCAL.*
-*.REMOTE.*
-
-# Components #
-##############
-
-/build
-/components
diff --git a/.npmignore b/.npmignore
index 9daeafb..cd39b77 100644
--- a/.npmignore
+++ b/.npmignore
@@ -1 +1,3 @@
-test
+coverage/
+test/
+.travis.yml
diff --git a/.travis.yml b/.travis.yml
index 99cdc74..1ff243c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -3,3 +3,9 @@ node_js:
   - "0.8"
   - "0.10"
   - "0.11"
+matrix:
+  allow_failures:
+    - node_js: "0.11"
+  fast_finish: true
+script: "npm run-script test-travis"
+after_script: "npm install coveralls at 2.10.0 && cat ./coverage/lcov.info | coveralls"
diff --git a/History.md b/History.md
index 442e1d3..423a29d 100644
--- a/History.md
+++ b/History.md
@@ -1,3 +1,38 @@
+1.2.3 / 2014-06-11
+==================
+
+  * deps: send at 0.4.3
+    - Do not throw un-catchable error on file open race condition
+    - Use `escape-html` for HTML escaping
+    - deps: debug at 1.0.2
+    - deps: finished at 1.2.2
+    - deps: fresh at 0.2.2
+
+1.2.2 / 2014-06-09
+==================
+
+  * deps: send at 0.4.2
+    - fix "event emitter leak" warnings
+    - deps: debug at 1.0.1
+    - deps: finished at 1.2.1
+
+1.2.1 / 2014-06-02
+==================
+
+  * use `escape-html` for escaping
+  * deps: send at 0.4.1
+    - Send `max-age` in `Cache-Control` in correct format
+
+1.2.0 / 2014-05-29
+==================
+
+  * deps: send at 0.4.0
+    - Calculate ETag with md5 for reduced collisions
+    - Fix wrong behavior when index file matches directory
+    - Ignore stream errors after request ends
+    - Skip directories in index file search
+    - deps: debug at 0.8.1
+
 1.1.0 / 2014-04-24
 ==================
 
diff --git a/Readme.md b/Readme.md
index af1caaa..177bebc 100644
--- a/Readme.md
+++ b/Readme.md
@@ -1,19 +1,68 @@
-# Serve Static
+# serve-static
+
+[![NPM version](https://badge.fury.io/js/serve-static.svg)](http://badge.fury.io/js/serve-static)
+[![Build Status](https://travis-ci.org/expressjs/serve-static.svg?branch=master)](https://travis-ci.org/expressjs/serve-static)
+[![Coverage Status](https://img.shields.io/coveralls/expressjs/serve-static.svg?branch=master)](https://coveralls.io/r/expressjs/serve-static)
 
 Previously `connect.static()`.
 
-[![Build Status](https://travis-ci.org/expressjs/serve-static.svg?branch=master)](https://travis-ci.org/expressjs/serve-static)
+## Install
+
+```sh
+$ npm install serve-static
+```
+
+## API
+
+```js
+var serveStatic = require('serve-static')
+```
+
+### serveStatic(root, options)
+
+Create a new middleware function to serve files from within a given root
+directory. The file to serve will be determined by combining `req.url`
+with the provided root directory.
+
+Options:
+
+- `hidden` Allow transfer of hidden files. defaults to `false`
+- `index` Default file name, defaults to `'index.html'`
+- `maxAge` Browser cache maxAge in milliseconds. defaults to `0`
+- `redirect` Redirect to trailing "/" when the pathname is a dir. defaults to `true`
+
+## Examples
+
+### Serve files with vanilla node.js http server
+
+```js
+var finalhandler = require('finalhandler')
+var http = require('http')
+var serveStatic = require('serve-static')
+
+// Serve up public/ftp folder
+var serve = serveStatic('public/ftp', {'index': ['index.html', 'index.htm']})
+
+// Create server
+var server = http.createServer(function(req, res){
+  var done = finalhandler(req, res)
+  serve(req, res, done)
+})
+
+// Listen
+server.listen(3000)
+```
 
-Usage:
+### Serve all files from ftp folder
 
 ```js
-var connect = require('connect');
-var serveStatic = require('serve-static');
+var connect = require('connect')
+var serveStatic = require('serve-static')
 
-var app = connect();
+var app = connect()
 
-app.use(serveStatic('public/ftp', {'index': ['default.html', 'default.htm']}));
-app.listen();
+app.use(serveStatic('public/ftp', {'index': ['default.html', 'default.htm']}))
+app.listen(3000)
 ```
 
 ## License
diff --git a/index.js b/index.js
index d0043fb..1be89c7 100644
--- a/index.js
+++ b/index.js
@@ -1,5 +1,5 @@
 /*!
- * Connect - static
+ * serve-static
  * Copyright(c) 2010 Sencha Inc.
  * Copyright(c) 2011 TJ Holowaychuk
  * Copyright(c) 2014 Douglas Christopher Wilson
@@ -10,6 +10,7 @@
  * Module dependencies.
  */
 
+var escapeHtml = require('escape-html');
 var parseurl = require('parseurl');
 var resolve = require('path').resolve;
 var send = require('send');
@@ -79,7 +80,7 @@ exports = module.exports = function(root, options){
       target = url.format(originalUrl);
       res.statusCode = 303;
       res.setHeader('Location', target);
-      res.end('Redirecting to ' + escape(target));
+      res.end('Redirecting to ' + escapeHtml(target));
     }
 
     function error(err) {
@@ -104,22 +105,6 @@ exports = module.exports = function(root, options){
 exports.mime = send.mime;
 
 /**
- * Escape the given string of `html`.
- *
- * @param {String} html
- * @return {String}
- * @api private
- */
-
-function escape(html) {
-  return String(html)
-    .replace(/&(?!\w+;)/g, '&')
-    .replace(/</g, '<')
-    .replace(/>/g, '>')
-    .replace(/"/g, '"');
-};
-
-/**
  * Shallow clone a single object.
  *
  * @param {Object} obj
diff --git a/package.json b/package.json
index 1636a66..725656a 100644
--- a/package.json
+++ b/package.json
@@ -1,30 +1,27 @@
 {
   "name": "serve-static",
   "description": "Serve static files",
-  "version": "1.1.0",
+  "version": "1.2.3",
   "author": "Douglas Christopher Wilson <doug at somethingdoug.com>",
   "license": "MIT",
-  "repository": {
-    "type": "git",
-    "url": "https://github.com/expressjs/serve-static.git"
-  },
-  "bugs": {
-    "url": "https://github.com/expressjs/serve-static/issues"
-  },
+  "repository": "expressjs/serve-static",
   "dependencies": {
+    "escape-html": "1.0.1",
     "parseurl": "1.0.1",
-    "send": "0.3.0"
+    "send": "0.4.3"
   },
   "devDependencies": {
-    "connect": "~2.14.1",
-    "mocha": "~1.18.2",
-    "should": "~3.3.0",
-    "supertest": "~0.11.0"
+    "istanbul": "0.2.10",
+    "mocha": "~1.20.0",
+    "should": "~4.0.0",
+    "supertest": "~0.13.0"
   },
   "engines": {
     "node": ">= 0.8.0"
   },
   "scripts": {
-    "test": "mocha --reporter spec --require should"
+    "test": "mocha --reporter dot --require should test/",
+    "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --require should test/",
+    "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --require should test/"
   }
 }
diff --git a/test/test.js b/test/test.js
index d1a37f5..987cf0e 100644
--- a/test/test.js
+++ b/test/test.js
@@ -1,7 +1,4 @@
 
-process.env.NODE_ENV = 'test';
-
-var connect = require('connect');
 var http = require('http');
 var path = require('path');
 var request = require('supertest');
@@ -18,9 +15,6 @@ describe('serveStatic()', function(){
     before(function () {
       server = createServer();
     });
-    after(function (done) {
-      server.close(done);
-    });
 
     it('should serve static files', function(done){
       request(server)
@@ -129,9 +123,6 @@ describe('serveStatic()', function(){
     before(function () {
       server = createServer('.');
     });
-    after(function (done) {
-      server.close(done);
-    });
 
     it('should be served with "."', function(done){
       var dest = relative.split(path.sep).join('/');
@@ -146,9 +137,6 @@ describe('serveStatic()', function(){
     before(function () {
       server = createServer(fixtures, {'hidden': true});
     });
-    after(function (done) {
-      server.close(done);
-    });
 
     it('should be served when hidden: true is given', function(done){
       request(server)
@@ -162,9 +150,6 @@ describe('serveStatic()', function(){
     before(function () {
       server = createServer(fixtures, {'maxAge': Infinity});
     });
-    after(function (done) {
-      server.close(done);
-    });
 
     it('should be reasonable when infinite', function(done){
       request(server)
@@ -179,9 +164,6 @@ describe('serveStatic()', function(){
     before(function () {
       server = createServer();
     });
-    after(function (done) {
-      server.close(done);
-    });
 
     it('should respond with 403 Forbidden', function(done){
       request(server)
@@ -201,9 +183,6 @@ describe('serveStatic()', function(){
     before(function () {
       server = createServer();
     });
-    after(function (done) {
-      server.close(done);
-    });
 
     it('should next()', function(done){
       request(server)
@@ -217,9 +196,6 @@ describe('serveStatic()', function(){
     before(function () {
       server = createServer();
     });
-    after(function (done) {
-      server.close(done);
-    });
 
     it('should support byte ranges', function(done){
       request(server)
@@ -319,9 +295,6 @@ describe('serveStatic()', function(){
     before(function () {
       server = createServer();
     });
-    after(function (done) {
-      server.close(done);
-    });
 
     it('should respond with 400', function(done){
       request(server)
@@ -335,9 +308,6 @@ describe('serveStatic()', function(){
     before(function () {
       server = createServer();
     });
-    after(function (done) {
-      server.close(done);
-    });
 
     it('should next()', function(done){
       var path = Array(100).join('foobar');
@@ -353,9 +323,6 @@ describe('serveStatic()', function(){
     before(function () {
       server = createServer();
     });
-    after(function (done) {
-      server.close(done);
-    });
 
     it('should next()', function(done) {
       request(server)
@@ -367,12 +334,10 @@ describe('serveStatic()', function(){
   describe('when index at mount point', function(){
     var server;
     before(function () {
-      var app = connect();
-      app.use('/users', serveStatic('test/fixtures/users'));
-      server = app.listen();
-    });
-    after(function (done) {
-      server.close(done);
+      server = createServer('test/fixtures/users', null, function (req) {
+        req.originalUrl = req.url;
+        req.url = '/' + req.url.split('/').slice(2).join('/');
+      });
     });
 
     it('should redirect correctly', function (done) {
@@ -386,12 +351,10 @@ describe('serveStatic()', function(){
   describe('when mounted', function(){
     var server;
     before(function () {
-      var app = connect();
-      app.use('/static', serveStatic(fixtures));
-      server = app.listen();
-    });
-    after(function (done) {
-      server.close(done);
+      server = createServer(fixtures, null, function (req) {
+        req.originalUrl = req.url;
+        req.url = '/' + req.url.split('/').slice(2).join('/');
+      });
     });
 
     it('should redirect relative to the originalUrl', function(done){
@@ -405,22 +368,10 @@ describe('serveStatic()', function(){
   describe('when responding non-2xx or 304', function(){
     var server;
     before(function () {
-      var app = connect();
       var n = 0;
-
-      app.use(function(req, res, next){
-        switch (n++) {
-          case 0: return next();
-          case 1: res.statusCode = 500; return next();
-        }
+      server = createServer(fixtures, null, function (req, res) {
+        if (n++) res.statusCode = 500;
       });
-
-      app.use(serveStatic(fixtures));
-
-      server = app.listen();
-    });
-    after(function (done) {
-      server.close(done);
     });
 
     it('should respond as-is', function(done){
@@ -436,38 +387,18 @@ describe('serveStatic()', function(){
       });
     });
   });
-
-  describe('raw http server', function(){
-    var server;
-    before(function () {
-      var middleware = serveStatic(fixtures);
-      server = http.createServer(function (req, res) {
-        middleware(req, res, function (err) {
-          res.statusCode = err ? 500 : 404;
-          res.end(err ? err.stack : '');
-        });
-      });
-      server.listen();
-    });
-    after(function (done) {
-      server.close(done);
-    });
-
-    it('should work on raw node.js http servers', function(done){
-      request(server)
-      .get('/todo.txt')
-      .expect(200, '- groceries', done);
-    });
-  });
 });
 
-function createServer(dir, opts) {
-  var app = connect();
+function createServer(dir, opts, fn) {
   dir = dir || fixtures;
-  app.use(serveStatic(dir, opts));
-  app.use(function(req, res){
-    res.statusCode = 404;
-    res.end('sorry!');
+
+  var _serve = serveStatic(dir, opts);
+
+  return http.createServer(function (req, res) {
+    fn && fn(req, res);
+    _serve(req, res, function (err) {
+      res.statusCode = err ? (err.status || 500) : 404;
+      res.end(err ? err.stack : 'sorry!');
+    });
   });
-  return app.listen();
 }

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



More information about the Pkg-javascript-commits mailing list