Comparing version 0.0.1 to 0.0.2
20
index.js
@@ -47,2 +47,3 @@ var send = require("send"), | ||
options = options || {}; | ||
var redirect = options.redirect !== false; | ||
@@ -63,3 +64,3 @@ function getVersionedPath(p) { | ||
send(req, filePath) | ||
var sent = send(req, filePath) | ||
.maxage(filePath == req.url ? 0 : 1000 * 60 * 60 * 23 * 365) | ||
@@ -69,5 +70,17 @@ .index(options.index || "index.html") | ||
.root(root) | ||
.pipe(res); | ||
sent.pipe(res); | ||
return sent; | ||
} | ||
function middleware(req, res, next) { | ||
if(req.method !== "GET" && req.method !== "HEAD") return next(); | ||
var stream = serve(req, res); | ||
stream.on("error", function(err) { | ||
if(err.status == 404) return next(); | ||
return next(err); | ||
}); | ||
} | ||
return { | ||
@@ -77,4 +90,5 @@ _versions: versions, | ||
stripVersion: stripVersion, | ||
serve: serve | ||
serve: serve, | ||
middleware: middleware | ||
} | ||
} |
{ | ||
"name": "staticify", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "A better static asset handler for node.js", | ||
@@ -15,3 +15,10 @@ "main": "index.js", | ||
"license": "MIT", | ||
"keywords": ["static", "asset", "versioning", "caching", "express", "expressjs"], | ||
"keywords": [ | ||
"static", | ||
"asset", | ||
"versioning", | ||
"caching", | ||
"express", | ||
"expressjs" | ||
], | ||
"dependencies": { | ||
@@ -18,0 +25,0 @@ "send": "~0.2.0" |
@@ -60,2 +60,34 @@ var should = require("should"), | ||
}); | ||
it("should 404 correctly", function(done) { | ||
http.get("http://localhost:12321/non.existant.file.js", function(res) { | ||
res.statusCode.should.equal(404); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
describe(".middlware", function() { | ||
var server; | ||
before(function(done) { | ||
server = http.createServer(); | ||
server.listen(12321, done); | ||
}); | ||
after(function(done) { server.close(done); }); | ||
it("should call next without error if 404", function(done) { | ||
server.once("request", function(req, res) { | ||
staticify.middleware(req, res, function(err) { | ||
res.statusCode.should.not.equal(404); | ||
should.not.exist(err); | ||
res.end(); | ||
done(); | ||
}); | ||
}); | ||
http.get("http://localhost:12321/non.existant.file.js"); | ||
}); | ||
}); |
5723
148