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
app.get('/-/static/:filename', function(req, res, next) {
var file = __dirname + '/static/' + req.params.filename
fs.exists(file, function(exists) {
if (exists) {
res.sendfile(file)
res.sendfile(file, function(err) {
if (err.status === 404) {
next()
} else {
next( Error[404]('File Not Found') )
next(err)
}
})
})

View File

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