Releases: honojs/hono
v4.2.0
Hono v4.2.0 is now available! Let's take a look at the new features.
Added more algorithms for JWT
The number of algorithms that JWT util can handle has increased from only 3 to 13! This means that JWT util now implements many of the algorithms supported by JWT.
- HS256
- HS384
- HS512
- RS256
- RS384
- RS512
- PS256
- PS384
- PS512
- ES256
- ES384
- ES512
- EdDSA
You can use these algorithms from the JWT middleware or JWT helpers. Thanks @Code-Hex!
Method Override Middleware
Method Override Middleware has been added. This middleware override the method of the real request with the specified method.
HTML form
does not allow you to send a DELETE method request. Instead, by sending an input with name
as _method
and a value of DELETE
, you can call the handler registered in app.delete()
.
const app = new Hono()
// If no options are specified, the value of `_method` in the form,
// e.g. DELETE, is used as the method.
app.use('/posts', methodOverride({ app }))
app.delete('/posts', (c) => {
// ....
})
Trailing Slash Middleware
Trailing Slash Middleware resolves the handling of Trailing Slashes in GET requests. You can use appendTrailingSlash
and trimTrailingSlash
functions.
For example, it redirects a GET request to /about/me
to /about/me/
.
import { Hono } from 'hono'
import { appendTrailingSlash } from 'hono/trailing-slash'
const app = new Hono({ strict: true })
app.use(appendTrailingSlash())
app.get('/about/me/', (c) => c.text('With Trailing Slash'))
Thanks @rnmeow!
Other features
- SSG Helper - Support
extensionMap
#2382 - JSX/DOM - Add
userId
hook #2389 - JWT Middleware - Improve error handling #2406
- Request - Cache the body for re-using #2416
- JWT Util - Add type helper to
payload
#2424 - CORS Middleware - Pass context to
options.origin
function #2436 - Cache Middleware - Support for the
vary
header option #2426 - HTTP Exception - Add
cause
option #2224 - Logger - Support
NO_COLOR
#2228 - JWT Middleware - Add
JwtTokenInvalid
object ascause
when JWT is invalid #2448 - Bearer Auth Middleware - Add
verifyToken
option #2449 - Basic Auth Middleware - Add
verifyUser
option #2450
All Updates
- feat(jwt): supported RS256, RS384, RS512 algorithm for JWT by @Code-Hex in #2339
- added remain algorithm for JWT by @Code-Hex in #2352
- acceptable CryptoKey in JWT sign and verify by @Code-Hex in #2373
- feat(ssg): Support
extentionMap
by @watany-dev in #2382 - feat(jwt): support remaining algorithms by @yusukebe in #2368
- feat(jsx): add useId hook by @usualoma in #2389
- feat(middleware/jwt): improve error handling by @tfkhdyt in #2406
- feat(request): cache body for reusing by @yusukebe in #2416
- feat(jwt): Add type helper to
payload
by @nakasyou in #2424 - feat: introduce Method Override Middleware by @yusukebe in #2420
- feat(middleware/cors): pass context to options.origin function by @okmr-d in #2436
- feat: support for
vary
header in cache middleware by @naporin0624 in #2426 - feat: add middlewares resolve trailing slashes on GET request by @rnmeow in #2408
- test: stub
crypto
if not exist by @yusukebe in #2445 - feat(jwt): literal typed
alg
option value by @yusukebe in #2446 - test(ssg): add test for content-type includes
;
by @yusukebe in #2447 - feat(jwt): add
JwtTokenInvalid
object ascause
when JWT is invalid by @yusukebe in #2448 - feat(bearer-auth): add
verifyToken
option by @yusukebe in #2449 - feat(basic-auth): add
verifyUser
option by @yusukebe in #2450 - Next by @yusukebe in #2454
New Contributors
- @tfkhdyt made their first contribution in #2406
- @okmr-d made their first contribution in #2436
- @naporin0624 made their first contribution in #2426
- @rnmeow made their first contribution in #2408
Full Changelog: v4.1.7...v4.2.0
v4.2.0-rc.1
This is a pre-release.
v4.1.7
v4.1.6
v4.1.5
What's Changed
- perf: Don't use
Arrap.prototype.map
if it is not needed return value by @nakasyou in #2419 - fix(aws-lambda): handle response without body (#2401) by @KnisterPeter in #2413
- fix(validator):
await
cached contents by @yusukebe in #2430
New Contributors
- @KnisterPeter made their first contribution in #2413
Full Changelog: v4.1.4...v4.1.5
v4.1.4
v4.1.3
What's Changed
- fix(deno): export jwt helpers for Deno in
src/helper.ts
by @yusukebe in #2385 - fix(jsx): use self closing tag only if element has no children by @usualoma in #2384
- feat(ssg): Support asynchronous hooks by @watany-dev in #2381
- fix(validator): use cached body for
json
andform
validation by @yusukebe in #2392 - fix(jsx): escape attribute value for "style" by @usualoma in #2390
Full Changelog: v4.1.2...v4.1.3
v4.1.2
What's Changed
- feat(utils/cookie): Typesafe cookie options by @Jxck in #2350
- fix(router): accept reg exp meta characters in path by @usualoma in #2375
- perf(utils/url): use
slice
+indexOf
forgetPath()
by @yusukebe in #2376 - fix(router): wildcard paths when using js reserved words (like constructor and proto) by @lmcarreiro in #2357
- fix(types):
MergePath
merge blank paths correctly by @yusukebe in #2365
New Contributors
- @lmcarreiro made their first contribution in #2357
Full Changelog: v4.1.1...v4.1.2
v4.1.1
What's Changed
- fix(context): export
ExecutionContext
fromhono
by @yusukebe in #2346 - fix(client): Remove trailing slash from /index for precise path matching by @poteboy in #2344
- ci: fix bun version for
denoify
by @yusukebe in #2362 - refactor(jsx-renderer): remove unnecessary comments for eslint by @yusukebe in #2361
- fix(lambda-edge): Lambda@Edge GET/HEAD body error. by @trkbt10 in #2351
- fix(jsx-renderer): don't overwrite headers if stream is
true
by @yusukebe in #2363 - fix(context): set headers correctly if it has
this.#headers
by @yusukebe in #2364 - fix(streaming): Fix stream SSE, not necessary close stream. by @damianpumar in #2320
New Contributors
- @poteboy made their first contribution in #2344
- @trkbt10 made their first contribution in #2351
- @damianpumar made their first contribution in #2320
Full Changelog: v4.1.0...v4.1.1
v4.1.0
Hono v4.1.0 is now available! Let's take a look at the new features.
WebSocket Helper
Now Hono supports WebSockets! With WebSocket helper, you can easily handle WebSockets in your application. Currently, Cloudflare Workers / Pages, Deno, and Bun adapters are available.
const app = new Hono()
app.get(
'/ws',
upgradeWebSocket((c) => {
return {
onMessage(event, ws) {
console.log(`Message from client: ${event.data}`)
ws.send('Hello from server!')
},
onClose: () => {
console.log('Connection closed')
}
}
})
)
PRC mode is now also supported for WebSockets endpoints. The following is a demo.
Thanks @nakasyou!
Body Limit Middleware
Introducing Body Limit Middleware. This middleware can limit the file size of the request body.
const app = new Hono()
app.post(
'/upload',
bodyLimit({
maxSize: 50 * 1024, // 50kb
onError: (c) => {
return c.text('overflow :(', 413)
}
}),
async (c) => {
const body = await c.req.parseBody()
if (body['file'] instanceof File) {
console.log(`Got file sized: ${body['file'].size}`)
}
return c.text('pass :)')
}
)
Thanks @EdamAme-x and @usualoma!
ES2022
We made the target
in the tsconfig.json
as ES2022 instead of ES2020. So, the generated JavaScript files are now ES2022. That made the file size smaller! The following is the result of the minify and build of "Hello World" with Wrangler.
// ES2020
hono => Total Upload: 20.15 KiB / gzip: 7.42 KiB
hono/tiny => Total Upload: 12.74 KiB / gzip: 4.69 KiB
// ES2022
hono => Total Upload: 18.46 KiB / gzip: 7.09 KiB
hono/tiny => Total Upload: 11.12 KiB / gzip: 4.38 KiB
Performance has also been improved in some Node.js environments.
Other features
- Cookie Helper - Supports
__Secure-
and__Host- prefix
#2269 - Cookie Helper - Check bis condition #2314
- jsx/dom - Add more React staff #2197
- SSG - Generate files concurrently #2187
- HTTP Exception - Add
cause
option #2224 - Logger - Support
NO_COLOR
#2228
All Updates
- feat: Add a "cause" option to HTTPException by @Karibash in #2224
- feat(logger): support
NO_COLOR
by @ryuapp in #2228 - feat(cookie): add secure and host prefix support by @Datron in #2269
- feat(ssg): generate files concurrently by @usualoma in #2187
- feat(jsx): more react staff by @usualoma in #2197
- feat: introduce Body Limit Middleware using stream by @yusukebe in #2309
- feat: Introduce WebSocket Helper / Adapter by @nakasyou in #2265
- refactor(SSG): separate middleware logic by @watany-dev in #2315
- chore: bump up
@hono/node-server
by @yusukebe in #2323 - fix(body-limit): export
bodyLimit
for Deno by @yusukebe in #2324 - fix(websocket): export WebSocket helper for Deno by @yusukebe in #2325
- feat(cookie): Add Cookie bis condition check by @Jxck in #2314
- Next by @yusukebe in #2327
New Contributors
- @Karibash made their first contribution in #2224
- @Datron made their first contribution in #2269
- @Jxck made their first contribution in #2314
Full Changelog: v4.0.10...v4.1.0