Middleware usage in multi-file based hono app setup #4629
Andrew-Chen-Wang
started this conversation in
General
Replies: 1 comment
-
|
Routing priority issue It's like you're doing const app = new Hono()
.use(authMiddleware)
.post("/stripe/checkout", (c) => {
return c.json({ message: 'Checkout successful!' })
})
.route("/stripe", webhook)Handlers or middleware will be executed in registration order. To make it works use like const app = new Hono()
.route("/stripe", webhook)
.route("/stripe", checkout)I suggest you do the following export const app = new Hono()
.post("/checkout", authMiddleware, (c) => {
return c.json({ message: 'Checkout successful!' })
}) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I ran into something unexpected that may or may not be documented in the middleware (i.e. idk if I missed it). The problem is that if two routes share the same subroute, then the first middleware that appears applies to all apps. I have a setup like so:
Where webhook unexpectedly goes through the authMiddleware, even though I would think the authMiddleware only goes through the checkout endpoint.
Is this expected? If so, does this deserve to go into the docs?
Beta Was this translation helpful? Give feedback.
All reactions