Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sirv

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sirv - npm Package Compare versions

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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc