register middleware early
This commit is contained in:
parent
c054ca1f82
commit
85fa79518c
|
|
@ -37,12 +37,14 @@ export class Hype<
|
|||
BasePath extends string = '/'
|
||||
> extends Hono<E, S, BasePath> {
|
||||
props: HypeProps
|
||||
middlewareRegistered = false
|
||||
routesRegistered = false
|
||||
|
||||
constructor(props?: HypeProps & ConstructorParameters<typeof Hono<E, S, BasePath>>[0]) {
|
||||
super(props)
|
||||
|
||||
this.props = props ?? {}
|
||||
this.registerMiddleware()
|
||||
}
|
||||
|
||||
sse(path: string, handler: SSEHandler<E>) {
|
||||
|
|
@ -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) => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user