Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
backend ruleP2universalStack: Node/Express
expressmiddlewareorganization
Extract request setup into small named Express middleware
Move per-request setup (e.g. populating res.locals) into focused, documented middleware functions composed in the route chain rather than inline blocks.
PR: hegnar-bellsheep-web · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codejs
| 1 | app.get('/*', (req, res) => { res.locals.data = { event: 'pageview' }; serveIndex(req, res); }); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codejs
| 1 | function setDefaultPageView(_, res, next) { res.locals.data = { event: 'pageview' }; next(); } |
| 2 | app.use(setDefaultPageView); |
| 3 | app.get('/*', serveIndex); |
Explanation (EN)
Objašnjenje (HR)