Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix connect.static() 404 regression, pass next(). Closes #629

  • Loading branch information...
commit 8daa67e41bab322217bb11df8d9c4fd68d5a049a 1 parent eb3ac5b
@tj tj authored
Showing with 16 additions and 2 deletions.
  1. +6 −1 lib/middleware/static.js
  2. +10 −1 test/static.js
View
7 lib/middleware/static.js
@@ -64,11 +64,16 @@ exports = module.exports = function static(root, options){
res.end('Redirecting to ' + utils.escape(pathname) + '/');
}
+ function error(err) {
+ if (404 == err.status) return next();
+ next(err);
+ }
+
send(req, path)
.maxage(options.maxAge || 0)
.root(options.root)
.hidden(options.hidden)
- .on('error', next)
+ .on('error', error)
.on('directory', directory)
.pipe(res);
};
View
11 test/static.js
@@ -6,6 +6,11 @@ var fixtures = __dirname + '/fixtures';
var app = connect();
app.use(connect.static(fixtures));
+app.use(function(req, res){
+ res.statusCode = 404;
+ res.end('sorry!');
+});
+
describe('connect.static()', function(){
it('should serve static files', function(done){
app.request()
@@ -136,7 +141,11 @@ describe('connect.static()', function(){
it('should next()', function(done){
app.request()
.get('/does-not-exist')
- .expect(404, done);
+ .end(function(res){
+ res.should.have.status(404);
+ res.body.should.equal('sorry!');
+ done();
+ });
})
})
Please sign in to comment.
Something went wrong with that request. Please try again.