About Middleware
Reusable Hono middleware
Browse the snippets below to find the middleware implementation you need for your Hono project.
All Middleware Snippets
CORS Middleware
Environment-driven CORS configuration
- Environment-driven origins
- Production/development modes
- Validation helper
Rate Limiter
Rate limiting with multiple presets
- Default, auth, API, and strict presets
- Custom key generator
- RateLimit headers
Security Headers
Comprehensive security headers (like Helmet)
- Content Security Policy
- HSTS configuration
- XSS protection
JWT Authentication
JWT middleware with RBAC support
- JWT verification
- Role-based access control
- Token extraction
Zod Validation
Request validation with Zod and error formatting
- JSON body validation
- Query parameter validation
- URL param validation
Logger Middleware
Structured request logging with timing
- Request timing
- Color-coded output
- Status code logging
Error Handler
Global error handling with custom error classes
- Custom error classes
- Production-safe messages
- HTTP exception handling
How to Use
Install any snippet using the Hanma CLI:
npx hanma add --framework hono
For example, to install the first snippet:
npx hanma add hono-cors --framework hono