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.
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
- fix(tests): Lagon env test by @QuiiBz in #1209
- Fix replaceUrlParam to ignore regexp in path by @hyp3rflow in #1214
- Add Server-Timing API as middleware by @PassiDel in #1215
- docs: add a svg logo image by @yusukebe in #1217
- feat(adapter): AWS Lambda Adapter supports requests via Lambda@edge by @watany-dev in #1210
- chore(ci): Update Action by @watany-dev in #1222
- fix(mount): include query params by @yusukebe in #1224
- fix(lambda-edge): update schema and refactor by @watany-dev in #1230
- feat(lambda-edge): pass the
context
andcallback
as env by @yusukebe in #1229
New Contributors
- @hyp3rflow made their first contribution in #1214
- @PassiDel made their first contribution in #1215
Full Changelog: v3.2.7...v3.3.0