Vafast Middleware Overview
Official Vafast plugins are installed as needed. Most are server.use(...) middleware; a few are utility libraries (see the description column).
Official Plugins
| Name | Description | Install |
|---|---|---|
| Auth Middleware | JWT / API key / app hard auth against an auth-server | npm i @vafast/auth-middleware |
| Bearer | Extract the Bearer token (no signature verification) | npm i @vafast/bearer |
| Compress | Brotli / gzip / deflate response compression | npm i @vafast/compress |
| Cookie | Cookie parsing, signing and Set-Cookie | npm i @vafast/cookie |
| CORS | Cross-origin resource sharing | npm i @vafast/cors |
| Cron | Scheduled jobs (not HTTP middleware) | npm i @vafast/cron |
| Helmet | Security-related response headers | npm i @vafast/helmet |
| HTML | HTML / JSX response helpers | npm i @vafast/html |
| IP | Client IP extraction | npm i @vafast/ip |
| JWT | JWT signing / verification utilities | npm i @vafast/jwt |
| Logger | Pino logger factory (not request middleware) | npm i @vafast/logger |
| OpenTelemetry | Distributed tracing | npm i @vafast/opentelemetry |
| Permission | Declarative permissions / RBAC (pluggable resolver) | npm i @vafast/permission |
| Rate Limit | Rate limiting | npm i @vafast/rate-limit |
| Request ID | Request ID generation and propagation | npm i @vafast/request-id |
| Request Logger | HTTP access log middleware | npm i @vafast/request-logger |
| Server Timing | Server-Timing performance header | npm i @vafast/server-timing |
| Static | Static file routes | npm i @vafast/static |
| Swagger | OpenAPI UI (hand-written spec) | npm i @vafast/swagger |
| Webhook | Declarative webhook dispatch | npm i @vafast/webhook |
| API Client | Type-safe API client | npm i @vafast/api-client |
Quick Example
typescript
import { Server, defineRoute, defineRoutes, serve } from 'vafast'
import { cors } from '@vafast/cors'
import { requestId } from '@vafast/request-id'
const routes = defineRoutes([
defineRoute({
method: 'GET',
path: '/',
handler: () => ({ ok: true }),
}),
])
const server = new Server(routes)
server.use(cors())
server.use(requestId())
serve({ fetch: server.fetch, port: 3000 })Related Links
- Middleware System — how
defineMiddlewareworks - Best Practices
- GitHub · npm