Skip to Content
Middleware (guards)Overview

Middleware (guards)

Path: hono-backend/src/middleware/

Middleware = bouncer that runs before your route handler.

Request → middleware → middleware → route handler → Response
FileQuestion it answers
request-idTag this request with a correlation id (X-Request-Id)
rate-limitIs this caller within their per-policy quota?
authIs there a valid logged-in user?
adminIs this user allowed to do admin things?
internal-keyIs this call from our worker with the secret key?

If middleware returns a response (401 / 403 / 429), the route never runs.

Order in index.ts (global mounts)

  1. cors(...) — origin gate
  2. requestIdMiddleware — assign / echo X-Request-Id
  3. rateLimitMiddleware — quota check (fails open if the limiter itself errors)

The remaining middleware (auth, admin, internal-key) is mounted per router as needed.

Last updated on