Skip to content

v3.3.0

Compare
Choose a tag to compare
@yusukebe yusukebe released this 11 Jul 01:38
· 686 commits to main since this release

v3.3.0 is now available. This release includes two new features. Let's explore them.

Server-Timing Middleware

Performance measurement is important. We're introducing the Server-Timing Middleware. This middleware allows you to measure the performance of processes in handlers using the Server-Timing API.

import { Hono } from 'hono'
import { endTime, setMetric, startTime, timing } from 'hono/timing'

const app = new Hono()

app.use('*', timing())

app.get('/', async (c) => {
  // add custom metrics
  setMetric(c, 'region', 'europe-west3')

  // add custom metrics with timing, must be in milliseconds
  setMetric(c, 'custom', 23.8, 'My custom Metric')

  // start a new timer
  startTime(c, 'db')
  const data = ['foo'] // DB process
  endTime(c, 'db')

  return c.json({ response: data })
})

export default app

You can view the results in tools like Chrome DevTools.

SS

Thanks to @PassiDel for contributing!

Lambda@Edge Adapter (Experimental)

We already have an AWS Lambda adapter, but it did not support Lambda@Edge. Now, the Lambda@Edge Adapter is available, although it's experimental. It's easy to use.

import { Hono } from 'hono'
import { handle } from 'hono/lambda-edge'

const app = new Hono()

app.get('/', (c) => c.text('Hello Hono!'))

export const handler = handle(app)

If you want to add Basic Auth and continue with request processing after verification, you can use c.env.callback()

import { Callback, CloudFrontRequest, handle } from 'hono/lambda-edge'

type Bindings = {
  callback: Callback
  request: CloudFrontRequest
}

const app = new Hono<{ Bindings: Bindings }>()

app.get(
  '*',
  basicAuth({
    username: 'a',
    password: 'b'
  })
)

app.get('/index.html', async (c, next) => {
  await next()
  c.env.callback(null, c.env.request)
})

export const handler = handle(app)

Special thanks to @watany-dev for this feature!

All Updates

New Contributors

Full Changelog: v3.2.7...v3.3.0