-
-
Notifications
You must be signed in to change notification settings - Fork 587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: pass context to onNotFound callback in serveStatic #1865
feat: pass context to onNotFound callback in serveStatic #1865
Conversation
I had no idea how to infer Middleware Handler's Context and pass it to onNotFound argument's context. |
c92892e
to
e978bd9
Compare
e978bd9
to
dfe060a
Compare
Please tell us along with specific examples. |
export type ServeStaticOptions<E extends Env> = {
root?: string
path?: string
rewriteRequestPath?: (path: string) => string
onNotFound?: (path: string, c: Context<E>) => void | Promise<void>
}
export const serveStatic = <E extends Env = Env>(options: ServeStaticOptions<E> = { root: '' }): MiddlewareHandler<E> => { If we could do something like this, we should be able to access envs type-safely from the callback context, but is this impossible with the current design? |
I struggled for hours to implement it, but I can't. Maybe it's impossible. I'll make more time to try. |
Okay, Thank you so much! |
Are you imagining the following code? If so, please implement that to make it true! const app = new Hono<Env>()
app.get(
'/static/*',
serveStatic<Env>({
onNotFound: (path, c) => {},
})
) |
Hi, @yusukebe. |
Thanks! But, also please change the |
…flare workers module's callback handler
@yusukebe fixed! thanks for finding it! |
Thanks! I'll merge this into "next" now. |
* feat: pass context to onNotFound callback in serveStatic * chore: denoify * test: update notFoundHandler's callback expect * feat: add Env generics for serveStatic to support `c.env` type in callback handler * feat: add Env generics for serveStatic to support c.env type in cloudflare workers module's callback handler
#1810
Author should do the followings, if applicable
yarn denoify
to generate files for Deno