Socket
Socket
Sign inDemoInstall

express-static

Package Overview
Dependencies
1
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.1 to 1.0.2

46

index.js

@@ -1,19 +0,37 @@

var fs = require('fs');
var fs = require('fs');
var url = require('url');
var path = require('path');
var mime = require('mime');
module.exports = function(root){
var Static = function(options){
this.options = options;
};
Static.prototype.send = function(req, res, next){
var uri = url.parse(req.url);
var pathname = uri.pathname;
if(/\/$/.test(pathname)) pathname += 'index.html';
var filename = path.join(this.options.root, pathname);
fs.stat(filename, function(err, stat){
if(err){
return next((~[ 'ENOENT' ].indexOf(err.code)) ? null : err);
}
var type = mime.lookup(filename);
var charset = mime.charsets.lookup(type);
res.setHeader('Content-Type' , type + (charset ? '; charset=' + charset : '' ));
res.setHeader('Content-Length', stat.size);
res.setHeader('Last-Modified' , stat.mtime.toUTCString());
fs.createReadStream(filename).pipe(res);
});
};
module.exports = function(root, options){
options = options || {};
console.log(root);
options.root = root;
var static = new Static(options);
return function(req, res, next){
var url = req.url;
if(/\/$/.test(url)) url += 'index.html';
var filename = path.join(root, url);
fs.exists(filename, function(exists){
if(exists){
fs.readFile(filename, { encoding: 'utf-8' }, function(err, data){
res.send(data);
});
}else{
next();
}
});
static.send.apply(static, arguments)
};
};
{
"name": "express-static",
"version": "1.0.1",
"version": "1.0.2",
"description": "",

@@ -25,3 +25,6 @@ "main": "index.js",

"express": "^4.9.6"
},
"dependencies": {
"mime": "*"
}
}
var express = require('express');
var logger = require('express-log');
var static = require('../index');

@@ -6,2 +7,3 @@

app.use(logger());
app.use(static(__dirname + '/public'));

@@ -8,0 +10,0 @@

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc