express-static
Advanced tools
Comparing version 1.2.4 to 1.2.5
12
index.js
@@ -19,2 +19,3 @@ const fs = require('fs'); | ||
options = defaults; | ||
root = path.resolve(root); | ||
/** | ||
@@ -29,4 +30,5 @@ * [function description] | ||
var pathname = url.parse(req.url).pathname; | ||
var filename = path.join(path.resolve(root), pathname); | ||
if(filename.endsWith('/') && typeof options.index === 'string') | ||
var filename = path.join(root, pathname); | ||
if(filename.indexOf(root) !== 0) return next(); | ||
if(filename.endsWith('/') && typeof options.index === 'string') | ||
filename += options.index; | ||
@@ -39,4 +41,4 @@ fs.stat(filename, function(err, stat){ | ||
} | ||
res.writeHead(301, { | ||
'Location': pathname + '/' | ||
res.writeHead(301, { | ||
'Location': pathname + '/' | ||
}); | ||
@@ -51,3 +53,3 @@ return res.end(); | ||
var charset = /^text\/|^application\/(javascript|json)/.test(type) ? 'UTF-8' : false; | ||
res.setHeader('Last-Modified', stat.mtime); | ||
res.setHeader('Last-Modified', new Date(stat.mtimeMs).toUTCString()); | ||
res.setHeader('Content-Length', stat.size); | ||
@@ -54,0 +56,0 @@ res.setHeader('Content-Type', type + (charset ? '; charset=' + charset : '')); |
{ | ||
"name": "express-static", | ||
"version": "1.2.4", | ||
"version": "1.2.5", | ||
"description": "serve static files for express", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
7264
108
10