This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Page404 = function (req, res, next) { res.status(404).render('page404', { title: "Oops 404!" }); } | |
| app.re404 = () => { app.remove(Page404); app.use(Page404); } | |
| app.re404(); | |
| // and call app.re404() function after adding new routes (eg. when loading submodules) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.remove = (handler, router) => { | |
| router = router || app._router; | |
| for (let i = 0; i < router.stack.length; i++) | |
| if (router.stack[i].handle == handler) { | |
| router.stack.splice(i, 1); | |
| break; | |
| } | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const isproduction = (process.env.NODE_ENV === 'production'); | |
| const origrenderfile = pug.renderFile; | |
| pug.renderFile = (path, options, fn) => { | |
| options.cache = isproduction; | |
| return origrenderfile(path, options, fn); | |
| }; |