serve-static
Advanced tools
Comparing version 1.0.4 to 1.1.0
@@ -0,1 +1,7 @@ | ||
1.1.0 / 2014-04-24 | ||
================== | ||
* Accept options directly to `send` module | ||
* deps: send@0.3.0 | ||
1.0.4 / 2014-04-07 | ||
@@ -2,0 +8,0 @@ ================== |
34
index.js
@@ -41,2 +41,4 @@ /*! | ||
* | ||
* Further options are forwarded on to `send`. | ||
* | ||
* @param {String} root | ||
@@ -49,3 +51,3 @@ * @param {Object} options | ||
exports = module.exports = function(root, options){ | ||
options = options || {}; | ||
options = extend({}, options); | ||
@@ -61,4 +63,9 @@ // root required | ||
// setup options for send | ||
options.maxage = options.maxage || options.maxAge || 0; | ||
options.root = root; | ||
return function staticMiddleware(req, res, next) { | ||
if ('GET' != req.method && 'HEAD' != req.method) return next(); | ||
var opts = extend({}, options); | ||
var originalUrl = url.parse(req.originalUrl || req.url); | ||
@@ -86,7 +93,3 @@ var path = parseurl(req).pathname; | ||
send(req, path) | ||
.maxage(options.maxAge || 0) | ||
.root(root) | ||
.index(options.index || 'index.html') | ||
.hidden(options.hidden) | ||
send(req, path, opts) | ||
.on('error', error) | ||
@@ -122,1 +125,20 @@ .on('directory', directory) | ||
}; | ||
/** | ||
* Shallow clone a single object. | ||
* | ||
* @param {Object} obj | ||
* @param {Object} source | ||
* @return {Object} | ||
* @api private | ||
*/ | ||
function extend(obj, source) { | ||
if (!source) return obj; | ||
for (var prop in source) { | ||
obj[prop] = source[prop]; | ||
} | ||
return obj; | ||
}; |
{ | ||
"name": "serve-static", | ||
"description": "Serve static files", | ||
"version": "1.0.4", | ||
"version": "1.1.0", | ||
"author": "Douglas Christopher Wilson <doug@somethingdoug.com>", | ||
@@ -16,3 +16,3 @@ "license": "MIT", | ||
"parseurl": "1.0.1", | ||
"send": "0.2.0" | ||
"send": "0.3.0" | ||
}, | ||
@@ -23,3 +23,3 @@ "devDependencies": { | ||
"should": "~3.3.0", | ||
"supertest": "~0.10.0" | ||
"supertest": "~0.11.0" | ||
}, | ||
@@ -26,0 +26,0 @@ "engines": { |
@@ -15,3 +15,3 @@ # Serve Static | ||
app.use(serveStatic('public/ftp', {'index': 'default.html'})); | ||
app.use(serveStatic('public/ftp', {'index': ['default.html', 'default.htm']})); | ||
app.listen(); | ||
@@ -18,0 +18,0 @@ ``` |
7043
118
+ Addedbuffer-crc32@0.2.1(transitive)
+ Addeddebug@0.8.0(transitive)
+ Addedsend@0.3.0(transitive)
- Removeddebug@4.3.4(transitive)
- Removedms@2.1.2(transitive)
- Removedsend@0.2.0(transitive)
Updatedsend@0.3.0