Skip to content

Releases: honojs/hono

v1.6.1

02 Jul 14:28
Compare
Choose a tag to compare

Summary

Added serve-static middleware for Deno.

import { serve } from 'https://deno.land/[email protected]/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

Full Changelog: v1.6.0...v1.6.1

v1.6.0

02 Jul 09:38
Compare
Choose a tag to compare

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/[email protected]/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

New Contributors

  • @equt made their first contribution in #335

Full Changelog: v1.5.2...v1.6.0

v1.5.2

27 Jun 05:25
Compare
Choose a tag to compare

Summary

  • c.req is now HonoRequest instead of Request.
  • 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

New Contributors

Full Changelog: v1.5.1...v1.5.2

v1.5.1

19 Jun 01:39
Compare
Choose a tag to compare

Summary

Added c.executionCtx. c.event is used for only Service Worker mode ( Not available in Module Workers mode).

What's Changed

New Contributors

Full Changelog: v1.5.0...v1.5.1

v1.5.0

17 Jun 09:58
Compare
Choose a tag to compare

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

13 Jun 03:00
Compare
Choose a tag to compare

Summary

This release includes BREAKING CHANGES.

[BREAKING CHANGES] JSX Middleware

  • h is obsolete, removed. Use jsx 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

Full Changelog: v1.4.6...v1.4.7

v1.4.6

10 Jun 09:56
Compare
Choose a tag to compare

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

New Contributors

Full Changelog: v1.4.5...v1.4.6

v1.4.5

07 Jun 01:27
Compare
Choose a tag to compare

Summary

Includes two features!

  • Bearer Auth middleware
  • Friendly error message

What's Changed

  • feat(middleware): add bearer auth middleware by @yusukebe in #299
  • feat: throw error if context is not finalized by @yusukebe in #301

Full Changelog: v1.4.4...v1.4.5

v1.4.4

04 Jun 11:13
Compare
Choose a tag to compare

Summary

A few bug fixes.

What's Changed

  • fix(status): make the status 401 for the invalid authorization info by @metrue in #296
  • fix: Import "declare global" for the Request interface explicitly. by @usualoma in #298

Full Changelog: v1.4.3...v1.4.4

v1.4.3

02 Jun 06:29
Compare
Choose a tag to compare

Summary

This release includes performance things. Hono is really really fast! And bug fixes for JWT middleware.
Thanks a lot, @usualoma and @metrue !

What's Changed

  • perf(conmpose): remove bind by @yusukebe in #283
  • perf(util): cache regex result for URL path(s) by @yusukebe in #284
  • chore(tsconfig): update es2017 to es2020 by @yusukebe in #285
  • minor typo fixes in readme by @nelsonjchen in #286
  • chore(benchmark): polyfill Request and Response by @yusukebe in #287
  • perf: Various performance tuning by @usualoma in #292
  • perf(util): use indexOf instead of RegExp.match for extracting URL. by @usualoma in #293
  • fix(token): correct 'WWW-Authenticate' header in response by @metrue in #294
  • fix(test): upgrade the miniflare to consume the fix on node18 by @metrue in #295

New Contributors

Full Changelog: v1.4.2...v1.4.3