HonoH
Hono13mo ago
meow

Abstracted routes but with context and types

I know there's some discussion of abstracted routes under https://hono.dev/docs/guides/best-practices. But there's no example which preserves the types from the context or middleware.

import hello from "./hello.ts"

type Env = {Variables: { db: typeof db }}

const factory = createFactory<Env>({
  initApp: (app) => {
    app.use(async (ctx, next) => {
      ctx.set("db", db)
      await next()
    })
  },
})

export const app = factory.createApp()

app.route("hello", hello)


How should I construct hello.ts so that the subroutes all have access to
db
in the context?
Was this page helpful?