Processed handler should be only one
See original GitHub issueIn the Iusse #189 , we decided to treat handlers and middleware as the same. We can write like these:
app.post('/a', basicAuth(), bodyParse(), (c) => c.text('a)')
This is good.
How about Handler + Handler pattern.
app.get('/a', (c) => {
console.log('a')
return c.text('a')
})
app.get('/:slug', (c) => {
console.log('slug')
return c.text('slug')
})
This Response body will be a
. This is expected.
BUT, in #258 I notice that every handler is processed. console.log
emits slug
, a
.
The reason:
- All routes including middleware are treated as the same.
- A path will match multiple routes = handlers or middleware.
- If multiple handlers are matched, every handler will be invoked.
- Route returning Response object is determined as the handler.
- We don’t know whether the route is a handler or Middleware until dispatching 😕
I think this design is not so good. Only one handler should be invoked. In this case, console.log
should emit only a
. So, we have to:
- Determine handler or middleware.
- Make only one handler invoked.
How can we do that?
Issue Analytics
- State:
- Created a year ago
- Comments:32 (16 by maintainers)
Top Results From Across the Web
Signal handler being called once per process - Stack Overflow
The problem is that cleanup is being called multiple times (once per each running process). How can I make it so cleanup is...
Read more >The DLQ handler rules table - IBM
The DLQ handler rules table defines how the DLQ handler is to process messages that arrive on the DLQ. ... You can specify...
Read more >Chain of Responsibility - Refactoring.Guru
If it can, it doesn't pass the request any further. So it's either only one handler that processes the request or none at...
Read more >Handler - Android Developers
A Handler allows you to send and process Message and Runnable objects ... This method is only for use in very special circumstances...
Read more >HandlerAdapters in Spring MVC - Baeldung
The DispatcherServlet then uses a HandlerAdapter to invoke this method. ... If a web application uses only controllers then we don't need to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey @yusukebe, thanks a lot for your great work! It works perfectly now 🤩
Hi @dan-lee !
We’ve released v1.4.1. https://github.com/honojs/hono/releases/tag/v1.4.1
This release includes the feature that you expected. Update routing priority and fixed the issue about GraghQL server middleware. The following code works well. Please check it out!