Astro Middleware

Middleware allows you to intercept requests and responses and inject logic dynamically before a page or endpoint is rendered.

Key Use Cases

  • Authentication: Checking for session cookies or JWTs.
  • Redirects: Handling legacy URLs or A/B testing.
  • Header Manipulation: Adding security headers or custom response headers.
  • Logging: Capturing performance metrics or request logs.