Skip to content

Instantly share code, notes, and snippets.

View BCsabaEngine's full-sized avatar

Csaba Balázs BCsabaEngine

  • MBH Bank Nyrt.
  • Budapest, HU
  • 22:52 (UTC +02:00)
View GitHub Profile
@BCsabaEngine
BCsabaEngine / common-route.js
Created October 8, 2020 10:26
Re404 - move 404 error handler at the end of routing
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)
@BCsabaEngine
BCsabaEngine / http.js
Created October 8, 2020 10:24
ExpressJS remove routing
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;
}
};
@BCsabaEngine
BCsabaEngine / routes-http.js
Last active October 8, 2020 10:21
PUG/JADE allow cache when production
const isproduction = (process.env.NODE_ENV === 'production');
const origrenderfile = pug.renderFile;
pug.renderFile = (path, options, fn) => {
options.cache = isproduction;
return origrenderfile(path, options, fn);
};