From 85fa79518c15daf8d124fac1816a37321b68ffe2 Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Wed, 28 Jan 2026 10:56:22 -0800 Subject: [PATCH] register middleware early --- src/index.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index 9f242c3..6ff6106 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -37,12 +37,14 @@ export class Hype< BasePath extends string = '/' > extends Hono { props: HypeProps + middlewareRegistered = false routesRegistered = false constructor(props?: HypeProps & ConstructorParameters>[0]) { super(props) this.props = props ?? {} + this.registerMiddleware() } sse(path: string, handler: SSEHandler) { @@ -68,9 +70,9 @@ export class Hype< }) } - registerRoutes() { - if (this.routesRegistered) return - this.routesRegistered = true + registerMiddleware() { + if (this.middlewareRegistered) return + this.middlewareRegistered = true // static assets in pub/ this.use('/*', serveStatic({ root: './pub' })) @@ -120,6 +122,11 @@ export class Hype< c.res = new Response(formatted, c.res) }) } + } + + registerRoutes() { + if (this.routesRegistered) return + this.routesRegistered = true // serve frontend js this.use('*', async (c, next) => {