mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-07 06:07:28 +02:00
Updated 404 for image handling
If an image or asset specified in static file handler is not found (ENOENT), then the 404 handler is now invoked (as opposed to prior, where a handled exception was thrown). Also, when requesting images inline that do not exist, NodeBB will now send back "404 Not Found" instead of the entire 404 page. If you access the broken link directly, you'll see the 404 page.
This commit is contained in:
@@ -174,10 +174,8 @@ function handle404(app, middleware) {
|
||||
res.type('text/javascript').status(200).send('');
|
||||
} else if (isLanguage.test(req.url)) {
|
||||
res.status(200).json({});
|
||||
} else if (req.path.startsWith(relativePath + '/uploads')) {
|
||||
res.status(404).send('');
|
||||
} else if (req.path === '/favicon.ico') {
|
||||
res.status(404).send('');
|
||||
} else if (req.path.startsWith(relativePath + '/uploads') || req.get('accept').indexOf('text/html') === -1 || req.path === '/favicon.ico') {
|
||||
res.sendStatus(404);
|
||||
} else if (req.accepts('html')) {
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
winston.warn('Route requested but not found: ' + req.url);
|
||||
|
||||
@@ -26,6 +26,15 @@ module.exports = function(app, middleware, controllers) {
|
||||
return next();
|
||||
}
|
||||
|
||||
res.sendFile(matches[0]);
|
||||
res.sendFile(matches[0], {}, function(err) {
|
||||
if (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
// File doesn't exist, this isn't an error, to send to 404 handler
|
||||
return next();
|
||||
} else {
|
||||
return next(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user