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 ruleP1stack specificStack: express
expressmiddlewareres.localsrequest-state
Set cross-cutting request state in middleware, not per route
A flag every renderer reads from `res.locals` should be assigned once in middleware; assigning it per route leaves sibling routes (another publication, preview) silently unset.
PR: hegnar-web#4698 FCK-3550 Drive ad suppression from the article flagCreated: Sep 7, 2026
Bad example
Old codets
| 1 | // article.ts and articlePreview.ts each do: |
| 2 | res.locals.adFree = isAdFreeArticle(article); |
| 3 | // server_kapital/routes/article.ts forgets to |
Explanation (EN)
Objašnjenje (HR)
Good example
New codets
| 1 | app.use((req, res, next) => { res.locals.adFree = ...; next(); }); |
Explanation (EN)
Objašnjenje (HR)