Built-in Middleware in Hono

From the Hono cheat sheet · Middleware · verified Jul 2026

Built-in Middleware

Common middleware included with Hono

typescript
import { cors } from 'hono/cors'
import { logger } from 'hono/logger'
import { prettyJSON } from 'hono/pretty-json'
import { compress } from 'hono/compress'
import { etag } from 'hono/etag'
import { secureHeaders } from 'hono/secure-headers'

const app = new Hono()

// Logging
app.use('*', logger())

// CORS
app.use('/api/*', cors({
  origin: 'https://example.com',
  allowMethods: ['GET', 'POST', 'PUT', 'DELETE'],
  allowHeaders: ['Content-Type', 'Authorization'],
  credentials: true,
}))

// Pretty JSON (add ?pretty to URLs)
app.use('*', prettyJSON())

// Response compression
app.use('*', compress())
💡 logger() adds request/response logging
⚡ cors() handles CORS preflight automatically
📌 secureHeaders() adds security headers (CSP, etc.)
🎯 compress() gzips responses for smaller payloads

More Hono tasks

Back to the full Hono cheat sheet