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 ruleP1universalStack: node
httpapirestheaders
Set the Allow header when rejecting a disallowed HTTP method
When returning 405 Method Not Allowed, set the Allow response header listing the accepted methods.
PR: hegnar-forum-web · org-mining-hist-2026-06Created: Jun 20, 2026
Bad example
Old codetypescript
| 1 | if (req.method !== 'POST') { |
| 2 | return res.status(405).json({ message: 'Method not allowed' }); |
| 3 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | if (req.method !== 'POST') { |
| 2 | res.setHeader('Allow', 'POST'); |
| 3 | return res.status(405).end(); |
| 4 | } |
Explanation (EN)
Objašnjenje (HR)