Comparing version 0.2.2 to 0.2.4
28
index.js
@@ -44,4 +44,3 @@ const fs = require('fs'); | ||
let notFound = opts.onNoMatch || is404; | ||
let setHeaders = opts.setHeaders || noop; | ||
let isNotFound = opts.onNoMatch || is404; | ||
let extensions = opts.extensions || ['html', 'htm']; | ||
@@ -51,7 +50,7 @@ | ||
return function (req, res, next) { | ||
let uri = req.path || req.pathname || parser(req).pathname; | ||
let uri = decodeURIComponent(req.path || req.pathname || parser(req).pathname); | ||
let arr = uri.includes('.') ? [uri] : toAssume(uri, extensions); | ||
let file = arr.map(x => join(dir, x)).find(fs.existsSync); | ||
if (!file) return next ? next() : notFound(res); | ||
res.setHeader('content-type', mime.getType(file)); | ||
if (!file) return next ? next() : isNotFound(res); | ||
res.setHeader('Content-Type', mime.getType(file)); | ||
fs.createReadStream(file).pipe(res); | ||
@@ -61,4 +60,5 @@ } | ||
let cc = opts.maxAge && `public,max-age=${opts.maxAge}`; | ||
cc && opts.immutable && (cc += ',immutable'); | ||
let setHeaders = opts.setHeaders || noop; | ||
let cc = opts.maxAge != null && `public,max-age=${opts.maxAge}`; | ||
if (cc && opts.immutable) cc += ',immutable'; | ||
@@ -72,8 +72,8 @@ opts.cwd = dir; | ||
headers = { | ||
'content-length': stats.size, | ||
'content-type': mime.getType(str), | ||
'last-modified': stats.mtime.toUTCString() | ||
'Content-Length': stats.size, | ||
'Content-Type': mime.getType(str), | ||
'Last-Modified': stats.mtime.toUTCString() | ||
}; | ||
cc && (headers['cache-control'] = cc); | ||
opts.etag && (headers['etag'] = toEtag(stats)); | ||
if (cc) headers['Cache-Control'] = cc; | ||
if (opts.etag) headers['ETag'] = toEtag(stats); | ||
FILES['/' + str.replace(/\\+/g, '/')] = { abs, stats, headers }; | ||
@@ -83,5 +83,5 @@ }); | ||
return function (req, res, next) { | ||
let pathname = req.path || req.pathname || parser(req).pathname; | ||
let pathname = decodeURIComponent(req.path || req.pathname || parser(req).pathname); | ||
let data = find(pathname, extensions); | ||
if (!data) return next ? next() : notFound(res); | ||
if (!data) return next ? next() : isNotFound(res); | ||
@@ -88,0 +88,0 @@ setHeaders(res, pathname, data.stats); |
{ | ||
"name": "sirv", | ||
"version": "0.2.2", | ||
"version": "0.2.4", | ||
"description": "The optimized & lightweight middleware for serving requests to static assets", | ||
@@ -5,0 +5,0 @@ "repository": "lukeed/sirv", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7897