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

staticify

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

staticify - npm Package Compare versions

Comparing version 0.0.9 to 0.0.10

.travis.yml

36

index.js

@@ -14,10 +14,10 @@ var send = require("send"),

files.forEach(function(file) {
var filePath = path.join(directory, file),
var filePath = path.posix.join(directory, file),
stat = fs.statSync(filePath);
if(stat.isDirectory()) {
if (stat.isDirectory()) {
buildVersionHash(filePath, root, versions); // Whee!
} else if(stat.isFile()) {
} else if (stat.isFile()) {
var hash = crypto.createHash("md5").update(fs.readFileSync(filePath, "utf8"), "utf8").digest("hex");
versions["/" + path.relative(root, filePath)] = hash;
versions["/" + path.posix.relative(root, filePath)] = hash;
}

@@ -34,5 +34,5 @@ });

var fileNameParts = fileName.split(".");
if(
if (
fileNameParts.length >= 3
&& fileNameParts[fileNameParts.length - 2].length == 32
&& fileNameParts[fileNameParts.length - 2].length === 32
&& /^[0-9a-f]{32}$/i.exec(fileNameParts[fileNameParts.length - 2])[0] === fileNameParts[fileNameParts.length - 2]

@@ -51,7 +51,8 @@ ) {

options = options || {};
var redirect = options.redirect !== false;
function getVersionedPath(p) {
// index.js -> index.<hash>.js
if(!versions[p]) return p;
if (!versions[p]) {
return p;
}

@@ -63,3 +64,3 @@ var fileName = path.basename(p),

return path.join(path.dirname(p), fileNameParts.join("."))
return path.posix.join(path.dirname(p), fileNameParts.join("."));
}

@@ -69,5 +70,6 @@

var filePath = stripVersion(url.parse(req.url).pathname);
var MAX_AGE = 1000 * 60 * 60 * 24 * 365; // 1 year
return send(req, filePath,{
maxage: filePath == req.url ? 0 : 1000 * 60 * 60 * 24 * 365,
return send(req, filePath, {
maxage: filePath === req.url ? 0 : MAX_AGE,
index: options.index || "index.html",

@@ -80,7 +82,11 @@ ignore: options.hidden,

function middleware(req, res, next) {
if(req.method !== "GET" && req.method !== "HEAD") return next();
if (req.method !== "GET" && req.method !== "HEAD") {
return next();
}
serve(req, res)
.on("error", function(err) {
if(err.status == 404) return next();
if (err.status === 404) {
return next();
}
return next(err);

@@ -113,3 +119,3 @@ })

replacePaths: replacePaths
}
}
};
};
{
"name": "staticify",
"version": "0.0.9",
"version": "0.0.10",
"description": "A better static asset handler for node.js",

@@ -8,6 +8,6 @@ "main": "index.js",

"type": "git",
"url": "git@github.com:errorception/staticify.git"
"url": "git+ssh://git@github.com/errorception/staticify.git"
},
"scripts": {
"test": "./node_modules/mocha/bin/mocha --reporter spec"
"test": "mocha --reporter spec"
},

@@ -28,6 +28,8 @@ "author": "Rakesh Pai <rakeshpai@errorception.com>",

"devDependencies": {
"should": "~13.1.1",
"mocha": "~4.0.1",
"through2": "~2.0.3"
"should": "~13.1.1"
},
"engines": {
"node": ">=4"
}
}

@@ -1,4 +0,9 @@

staticify
===
# staticify
[![NPM version](https://img.shields.io/npm/v/staticify.svg)](https://www.npmjs.com/package/staticify)
[![Linux Build Status](https://img.shields.io/travis/errorception/staticify/master.svg?label=Linux%20build)](https://travis-ci.org/errorception/staticify)
[![Windows Build status](https://img.shields.io/appveyor/ci/errorception/staticify/master.svg?label=Windows%20build)](https://ci.appveyor.com/project/errorception/staticify/branch/master)
[![dependencies Status](https://img.shields.io/david/errorception/staticify.svg)](https://david-dm.org/errorception/staticify)
[![devDependencies Status](https://img.shields.io/david/dev/errorception/staticify.svg)](https://david-dm.org/errorception/staticify?type=dev)
A better static asset handler for node.js / express.js

@@ -23,6 +28,6 @@

With express.js
---
## With express.js
```javascript
var path = require("path");
var staticify = require("staticify")(path.join(__dirname, "public"));

@@ -42,6 +47,6 @@

Usage
---
## Usage
Install from npm:
```

@@ -54,2 +59,3 @@ npm install staticify

```javascript
var path = require("path");
var statificy = require("staticify")(path.join(__dirname, "public"));

@@ -63,2 +69,3 @@ ```

Does the following transformation to the `path`, and returns immediately:
```javascript

@@ -87,3 +94,5 @@ staticify.getVersionedPath('/path/to/file.ext'); // --> /path/to/file.<md5 of the contents of file.ext>.ext

```
returns
```javascript

@@ -103,3 +112,3 @@ "body { background: url('/index.d766c4a983224a3696bc4913b9e47305.js') }"

Note, this function doesn't verify that the hash is valid. It simply finds what looks like a hash and strips it from the path.
Note, this function doesn't verify that the hash is valid. It simply finds what looks like a hash and strips it from the path.

@@ -118,4 +127,4 @@ ### .refresh()

License
---
MIT
## License
MIT
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