npm hono 1.4.0
v1.4.0

latest releases: 4.6.10, 4.6.9, 4.6.8...
2 years ago

BREAKING CHANGES!!

This release includes some breaking changes.

Only one handler will be processed

Before this release, it is possible multiple handlers will be dispatched.

app.get('/a', async c => {
    console.log('a')
    return c.text('a')
});
app.get('/:slug', async c => {
    console.log('slug')
    return c.text('slug')
})

Output is a, slug.

But from this release, only one handler will be dispatched.

app.get('/book/a', (c) => c.text('a')) // a
app.get('/book/:slug', (c) => c.text('common')) // common
GET /book/a ---> `a` // common will not be dispatched
GET /book/b ---> `common` // a will not be dispatched

Stop proceeding when the handler is dispatched

If you write middleware like these, please rewrite routing.

app.get('/api', (c) => {
  return c.text('foo')
}) // <--- stop process

app.use('/api/*', middleware()) // <--- not dispached!!

Rewrite to

app.use('/api/*', middleware()) // <--- dispached!!

app.get('/api', (c) => {
  return c.text('foo')
})

Routing Priority

Routing priority is fixed. Decided by the order of registration.

app.get('/api/*', 'c') // score 1.1 <--- `/*` is special wildcard
app.get('/api/:type/:id', 'd') // score 3.2
app.get('/api/posts/:id', 'e') // score 3.3
app.get('/api/posts/123', 'f') // score 3.4
app.get('/*/*/:id', 'g') // score 3.5
app.get('/api/posts/*/comment', 'h') // score 4.6 - not match
app.get('*', 'a') // score 0.7
app.get('*', 'b') // score 0.8
GET /api/posts/123
---> will match => c, d, e, f, b, a, b
---> sort by score => a, b, c, d, e, f, g

router option

routerClass option is obsolete. Use router option instead.

import { RegExpRouter } from 'hono/router/reg-exp-router'
const app = new Hono({ router: new RegExpRouter() })

What's Changed

  • fix(context): initialize status and header values after newResponse by @yusukebe in #261
  • fix(jwt): ensure the request does not continue if the jwt token is invalid or expired by @cdrx in #266
  • feat: adoption of a new sort order for routing in RegExpRouter by @usualoma in #267
  • feat(trie-router) : Routing with order specification by @yusukebe in #269
  • fix(router): fixed trie-router bugs by @yusukebe in #271
  • refactor(router): Make Router an interface, not a class by @usualoma in #268
  • feat: c.res is available before dispatching by @yusukebe in #272

New Contributors

  • @cdrx made their first contribution in #266

Full Changelog: v1.3.6...v1.4.0

Don't miss a new hono release

NewReleases is sending notifications on new releases.