handle 404 errors better

+ get rid of fs.exists
This commit is contained in:
Alex Kocharin 2014-11-12 19:25:33 +03:00
parent 100430227c
commit 7687965219
2 changed files with 7 additions and 4 deletions

View File

@ -45,11 +45,11 @@ module.exports = function(config, auth, storage) {
// Static // Static
app.get('/-/static/:filename', function(req, res, next) { app.get('/-/static/:filename', function(req, res, next) {
var file = __dirname + '/static/' + req.params.filename var file = __dirname + '/static/' + req.params.filename
fs.exists(file, function(exists) { res.sendfile(file, function(err) {
if (exists) { if (err.status === 404) {
res.sendfile(file) next()
} else { } else {
next( Error[404]('File Not Found') ) next(err)
} }
}) })
}) })

View File

@ -415,6 +415,9 @@ module.exports = function(config_hash) {
res.report_error(err) res.report_error(err)
}) })
app.get('/*', function(req, res, next) {
next( Error[404]('file not found') )
})
return app return app
} }