Reputation: 1742
I'm not getting any type hints from my Hono RPC client. I know there are warnings not to use the factory method, but as far as I knew this was the only way to have abstracted routes. I'm open to any way that allows me to have routes in separate files.
type Env = {
Variables: {
db: typeof db
mqtt: typeof mqtt
redis: typeof redis
}
}
function initApp(app: Hono<Env, BlankSchema, "/">) {
app.use(async (ctx, next) => {
ctx.set("db", db)
ctx.set("mqtt", mqtt)
ctx.set("redis", redis)
await next()
})
}
const factory = createFactory<Env>({ initApp })
export default factory
// ———————————————————————————————————————————
// Route Index
const app = factory.createApp()
.route("/", root)
.route("/config", config)
.route("/redis", redis)
export type App = typeof app
// ———————————————————————————————————————————
// Client
const client = hc<App>(`http://${HOSTNAME}:${PORT}`)
export default client
Upvotes: 0
Views: 84