About Middleware
Production middleware using Elysia's decorator patterns
Browse the snippets below to find the middleware implementation you need for your Elysia project.
All Middleware Snippets
Logger Middleware
HTTP request logging with timing and sensitive data masking
- Request/response timing
- Sensitive data masking
- Configurable exclusion paths
Rate Limiter
In-memory rate limiting with sliding window algorithm
- Sliding window algorithm
- Per-IP limiting
- Environment-driven config
Error Handler
Centralized error handling with custom error classes
- Custom error classes
- Consistent JSON responses
- Error logging
Security Headers
Security headers middleware with CSP, HSTS, and more
- Content-Security-Policy
- Strict-Transport-Security
- X-Frame-Options
Request ID
Request ID tracing for distributed systems
- Auto-generate request IDs
- Propagate from headers
- Logging correlation
Compression
Response compression using Bun's native gzip
- Bun native gzip
- Configurable threshold
- Content-type filtering
Timeout
Request timeout with configurable duration
- Configurable duration
- Path exclusions
- Environment-driven config
How to Use
Install any snippet using the Hanma CLI:
npx hanma add --framework elysia
For example, to install the first snippet:
npx hanma add elysia-logger --framework elysia