Comparing version 0.0.3 to 0.0.4
39
index.js
@@ -5,5 +5,3 @@ var send = require("send"), | ||
fs = require("fs"), | ||
through = require("through"), | ||
url = require("url"), | ||
split = require("split"); | ||
url = require("url"); | ||
@@ -66,6 +64,6 @@ function buildVersionHash(directory, root, versions) { | ||
function serve(req, res) { | ||
function serve(req) { | ||
var filePath = stripVersion(url.parse(req.url).pathname); | ||
var sent = send(req, filePath) | ||
return send(req, filePath) | ||
.maxage(filePath == req.url ? 0 : 1000 * 60 * 60 * 24 * 365) | ||
@@ -75,5 +73,2 @@ .index(options.index || "index.html") | ||
.root(root) | ||
sent.pipe(res); | ||
return sent; | ||
} | ||
@@ -84,22 +79,25 @@ | ||
var stream = serve(req, res); | ||
stream.on("error", function(err) { | ||
if(err.status == 404) return next(); | ||
return next(err); | ||
}); | ||
serve(req, res) | ||
.on("error", function(err) { | ||
if(err.status == 404) return next(); | ||
return next(err); | ||
}) | ||
.pipe(res); | ||
} | ||
function replacePaths() { | ||
function replacePaths(fileContents) { | ||
var urls = Object.keys(this._versions), | ||
versions = this._verisons; | ||
return split().pipe(through(function(data) { | ||
urls.forEach(function(url) { | ||
data = data.replace(url, getVersionedPath(url)); | ||
}); | ||
urls.forEach(function(url) { | ||
fileContents = fileContents.replace(url, getVersionedPath(url)); | ||
}); | ||
this.queue(data); | ||
})); | ||
return fileContents; | ||
} | ||
function refresh() { | ||
versions = buildVersionHash(root); | ||
} | ||
return { | ||
@@ -110,2 +108,3 @@ _versions: versions, | ||
serve: serve, | ||
refresh: refresh, | ||
middleware: middleware, | ||
@@ -112,0 +111,0 @@ replacePaths: replacePaths |
{ | ||
"name": "staticify", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "A better static asset handler for node.js", | ||
@@ -11,3 +11,3 @@ "main": "index.js", | ||
"scripts": { | ||
"test": "./node_modules/mocha/bin/mocha --reporter spec --watch" | ||
"test": "./node_modules/mocha/bin/mocha --reporter spec" | ||
}, | ||
@@ -25,10 +25,9 @@ "author": "Rakesh Pai <rakeshpai@errorception.com>", | ||
"dependencies": { | ||
"send": "~0.2.0", | ||
"split": "~0.3.0", | ||
"through": "~2.3.4" | ||
"send": "~0.2.0" | ||
}, | ||
"devDependencies": { | ||
"should": "~3.1.2", | ||
"mocha": "~1.17.1" | ||
"mocha": "~1.17.1", | ||
"through2": "~0.4.1" | ||
} | ||
} |
var should = require("should"), | ||
http = require("http"), | ||
through = require("through"), | ||
staticify = require("../")(__dirname + "/../"); | ||
staticify = require("../")(__dirname + "/../"), | ||
through2 = require("through2"); | ||
@@ -40,3 +40,5 @@ describe("constructor", function() { | ||
before(function(done) { | ||
server = http.createServer(staticify.serve); | ||
server = http.createServer(function(req, res) { | ||
staticify.serve(req).pipe(res); | ||
}); | ||
server.listen(12321, done); | ||
@@ -71,3 +73,3 @@ }); | ||
describe(".middlware", function() { | ||
describe(".middleware", function() { | ||
var server; | ||
@@ -85,3 +87,2 @@ | ||
staticify.middleware(req, res, function(err) { | ||
res.statusCode.should.not.equal(404); | ||
should.not.exist(err); | ||
@@ -99,13 +100,10 @@ | ||
describe(".replacePaths", function() { | ||
it("should replace paths in a stream, and output a stream", function(done) { | ||
var stream = through().pause().queue("body { background: url('/index.js') }").end(); | ||
stream.pipe(staticify.replacePaths()).on("data", function(data) { | ||
data.should.startWith("body { background: url('/index."); | ||
data.should.endWith("') }"); | ||
data.indexOf("index.js").should.equal(-1); | ||
data.should.match(/index\.[0-9a-f]{32}\.js/i); | ||
it("should replace paths in a stream, and output a stream", function() { | ||
var results = staticify.replacePaths("body { background: url('/index.js') }"); | ||
done(); | ||
}).resume(); | ||
results.should.startWith("body { background: url('/index."); | ||
results.should.endWith("') }"); | ||
results.indexOf("index.js").should.equal(-1); | ||
results.should.match(/index\.[0-9a-f]{32}\.js/i); | ||
}); | ||
}); |
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
1
6609
3
174
- Removedsplit@~0.3.0
- Removedthrough@~2.3.4
- Removedsplit@0.3.3(transitive)
- Removedthrough@2.3.8(transitive)