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) => {