diff --git a/controllers/errorsController.js b/controllers/errorsController.js index 1701432..a37cab6 100644 --- a/controllers/errorsController.js +++ b/controllers/errorsController.js @@ -11,7 +11,7 @@ const self = { .map(key => Number(key)) } -self.handlerError = (req, res, error) => { +self.handleError = (req, res, error) => { if (!res || res.headersSent) { console.error('Unexpected missing "res" object or headers alredy sent.') return console.trace() @@ -58,7 +58,7 @@ self.handlerError = (req, res, error) => { } } -self.handlerNotFound = (req, res) => { +self.handleNotFound = (req, res) => { res.setHeader('Cache-Control', 'no-store') return res.status(404).sendFile(path.join(paths.errorRoot, config.errorPages[404])) } diff --git a/lolisafe.js b/lolisafe.js index 745c9e4..4dc6222 100644 --- a/lolisafe.js +++ b/lolisafe.js @@ -41,6 +41,7 @@ const safe = new HyperExpress.Server({ trust_proxy: Boolean(config.trustProxy) }) +const errors = require('./controllers/errorsController') const paths = require('./controllers/pathsController') paths.initSync() const utils = require('./controllers/utilsController') @@ -364,10 +365,9 @@ safe.use('/api', api) } } - // Web server error handlers (must always be set after all routes/routers) - const errorsController = require('./controllers/errorsController') - safe.set_not_found_handler(errorsController.handlerNotFound) - safe.set_error_handler(errorsController.handlerError) + // Web server error handlers (must always be set after all routes/middlewares) + safe.set_not_found_handler(errors.handleNotFound) + safe.set_error_handler(errors.handleError) // Git hash if (config.showGitHash) { diff --git a/routes/album.js b/routes/album.js index 192654f..64bab45 100644 --- a/routes/album.js +++ b/routes/album.js @@ -8,7 +8,7 @@ const config = require('./../config') routes.get('/a/:identifier', async (req, res) => { const identifier = req.params.identifier if (identifier === undefined) { - return errors.handlerNotFound(req, res) + return errors.handleNotFound(req, res) } const album = await utils.db.table('albums') @@ -20,7 +20,7 @@ routes.get('/a/:identifier', async (req, res) => { .first() if (!album || album.public === 0) { - return errors.handlerNotFound(req, res) + return errors.handleNotFound(req, res) } const nojs = req.query.nojs !== undefined