Performance: Catch-all API routes
MEDIUM IMPACT
Catch-all API routes impact server response time and routing efficiency, which affects how quickly the page can load dynamic data.
export default function handler(req, res) { const { slug } = req.query; // Use slug array directly to handle dynamic paths flexibly res.status(200).json({ path: slug }); }
export default function handler(req, res) { const { slug } = req.query; if (slug.length === 1) { // handle /api/post } else if (slug.length === 2) { // handle /api/post/comment } else { res.status(404).end(); } }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual slug length checks with multiple conditions | 0 (server-side) | 0 | 0 | [X] Bad |
| Uniform catch-all handler using slug array directly | 0 (server-side) | 0 | 0 | [OK] Good |