Middleware

You might say

I have a dozen endpoints that all need login checks and request logging—where do I put that without copying it into every file?

A shared processing layer that runs in order before or after route handlers for tasks like auth, logging, or blockingWhen twenty endpoints require a signed-in user, putting session checks in an auth middleware stops unauthenticated requests with 401 before business code runs. Order and route matching matter: if /login is accidentally included in the auth matcher, the browser gets trapped in an infinite redirect loop.
HTTP Middleware

You can say this to an AI Agent

Ready to paste into Cursor, Claude Code, or Codex
Structured AI Agent prompt

Extract a request-logging middleware and an auth middleware: run logging before auth, scope auth only to protected paths like `/api/orders` and `/dashboard`, and exclude `/login`, `/health`, and static assets. Verify that unauthenticated `/api/orders` returns 401, `/login` returns 200 without a redirect loop, and blocked requests still appear in logs.

Want your Agent to translate plain-language UI ideas automatically?Install free VibeHub Skill →
Oil UI Pro. Push AI’s design skills to the limit. Usability, existing projects and stricter review.
Further reading