Releases: honojs/hono
v1.6.2
v1.6.1
Summary
Added serve-static
middleware for Deno.
import { serve } from 'https://deno.land/std@0.146.0/http/server.ts'
import { Hono, serveStatic } from 'https://deno.land/x/hono/mod.ts'
const app = new Hono()
app.get('/favicon.ico', serveStatic({ path: './public/favicon.ico' }))
//...
serve(app.fire())
What's Changed
- chore: rm
*.ts.test
from deno_dist by @yusukebe in #338 - feat: add
serve-static
middleware for deno by @yusukebe in #339
Full Changelog: v1.6.0...v1.6.1
v1.6.0
Summary
Now, Hono supports for Deno!! It's experimental but a super cool feature. You can import
Hono from deno.land/x
.
/** @jsx jsx */
import { serve } from 'https://deno.land/std@0.146.0/http/server.ts'
import { Hono, logger, poweredBy, basicAuth, jsx } from 'https://deno.land/x/hono/mod.ts'
const app = new Hono()
app.use('*', logger(), poweredBy())
app.get(
'/auth/*',
basicAuth({
username: 'deno',
password: 'isacool',
})
)
app.get('/', (c) => {
return c.html(<h1>Hello Deno!</h1>)
})
app.get('/auth/abc', (c) => c.text('You are authorized'))
serve(app.fire())
What's Changed
- refactor: enable
strictPropertyInitialization
by @yusukebe in #333 - feat(context): type JSON object as generic var
T
by @equt in #335 - feat: support for Deno! by @yusukebe in #336
- chore: add benchmark scripts for deno by @yusukebe in #337
New Contributors
Full Changelog: v1.5.2...v1.6.0
v1.5.2
Summary
c.req
is nowHonoRequest
instead ofRequest
.path
option has been added to serve-static middleware. You can write like a below:
app.get('/foo', (c) => {
return c.text('/foo')
})
// fallback
app.get('*', serveStatic({ path: './static/index.html' }))
What's Changed
- fix(typo) JSX README by @YukiYuigishi in #328
- refactor: make
HonoRequest
by @yusukebe in #330 - feat(serve-static): add
path
option by @yusukebe in #331
New Contributors
- @YukiYuigishi made their first contribution in #328
Full Changelog: v1.5.1...v1.5.2
v1.5.1
Summary
Added c.executionCtx
. c.event
is used for only Service Worker mode ( Not available in Module Workers mode).
What's Changed
- feat(context): add executionCtx to Context by @hansottowirtz in #326
New Contributors
- @hansottowirtz made their first contribution in #326
Full Changelog: v1.5.0...v1.5.1
v1.5.0
BREAKING CHANGES!!
This release includes BREAKING CHANGES.
Routing priority has been changed. The new rules are below:
Handlers or middleware will be executed in registration order.
app.get('/book/a', (c) => c.text('a')) // a
app.get('/book/:slug', (c) => c.text('common')) // common
GET /book/a ---> `a`
GET /book/b ---> `common`
When a handler is executed, the process will be stopped.
app.get('*', (c) => c.text('common')) // common
app.get('/foo', (c) => c.text('foo')) // foo
GET /foo ---> `common` // foo will not be dispatched
If you have the middleware that you want to execute, write the code above the handler.
app.use('*', logger())
app.get('/foo', (c) => c.text('foo'))
If you want a "fallback" handler, write the code below the other handler.
app.get('/foo', (c) => c.text('foo')) // foo
app.get('*', (c) => c.text('fallback')) // fallback
GET /bar ---> `fallback`
What's Changed
- refactor(reg-exp-router): Routes are returned in the registration order. by @usualoma in #324
- refactor(trie-router): routes are returned in the registration order by @yusukebe in #325
Full Changelog: v1.4.7...v1.5.0
v1.4.7
Summary
This release includes BREAKING CHANGES.
[BREAKING CHANGES] JSX Middleware
h
is obsolete, removed. Usejsx
instead.- Don't write
app.use('*', jsx())
. It's not needed. - If you want to return HTML, use
c.html()
You can write as below:
import { Hono } from 'hono'
import { jsx } from 'hono/jsx'
const app = new Hono()
app.get('/', (c) => {
return c.html(
'<!doctype html>' +
(
<html>
<body>
<p>Hono!</p>
</body>
</html>
)
)
})
app.fire()
html Middleware
We've added html Middleware. It's powerful to use with JSX middleware. For more information, see documentation
import { Hono } from 'hono'
import { html } from 'hono/html'
import { jsx } from 'hono/jsx'
const app = new Hono()
interface SiteData {
title: string
children?: any
}
const Layout = (props: SiteData) => html`<!DOCTYPE html>
<html>
<head>
<title>${props.title}</title>
</head>
<body>
${props.children}
</body>
</html>`
const Content = (props: { siteData: SiteData; name: string }) => (
<Layout {...props.siteData}>
<h1>Hello {props.name}</h1>
</Layout>
)
app.get('/:name', (c) => {
const { name } = c.req.param()
const props = {
name: name,
siteData: {
title: 'JSX with html sample',
},
}
return c.html(<Content {...props} />)
})
app.fire()
Others
- Implemented
Fragment
for JSX middleware.
What's Changed
- feat(middleware/jsx): We need Fragment. by @usualoma in #310
- feat: Introduce html template literals tag. by @usualoma in #312
- feat(utils/html): Introduce a function
raw
. by @usualoma in #316 - [BREAKING] refactor(jsx):
h
tojsx
, removeh
by @yusukebe in #318 - refactor(html): make
html
as middleware by @yusukebe in #319
Full Changelog: v1.4.6...v1.4.7
v1.4.6
Summary
Now, JSX MIddleware is available! You can write JSX for rendering HTML.
import { Hono } from 'hono'
import { h, jsx } from 'hono/jsx'
export const app = new Hono()
app.use('*', jsx())
const Layout = (props: { children?: string }) => {
return (
<html>
<body>{props.children}</body>
</html>
)
}
const Top = (props: { message: string }) => {
return (
<Layout>
<h1>{props.message}</h1>
</Layout>
)
}
app.get('/', (c) => {
const message = 'Hello! Hono!!'
return c.render(<Top message={message} />)
})
export default app
tsconfig.json
{
"compilerOptions": {
"jsx": "react",
"jsxFactory": "h"
}
}
Enjoy!
What's Changed
- feat:
notFound
support asyc/await by @yusukebe in #303 - Update README.md by @charl-kruger in #304
- Export
md5
function in src/utils/crypto.ts by @erhlee-bird in #305 - perf(utils/html): Improve performance
escape()
by @usualoma in #307 - feat(middleware/jsx): Support dangerouslySetInnerHTML and some special spec by @usualoma in #308
- feat(middleware/jsx): Introduce memo. by @usualoma in #309
- feat: jsx middleware by @yusukebe in #306
New Contributors
- @erhlee-bird made their first contribution in #305
Full Changelog: v1.4.5...v1.4.6