Colliding async routes don't work as expected
See original GitHub issue👋 If you have two synchronous routes that overlap as I’d expect:
app.get('/a', c => c.text('a'));
app.get('/:slug', c.text('slug'));
Requesting /a
returns a
, and requesting /b
returns slug
.
However, if these routes are asynchronous, then things don’t behave correctly:
app.get('/a', async c => {
await new Promise(resolve => setTimeout(resolve, 10));
return c.text('a');
});
app.get('/:slug', async c => {
await new Promise(resolve => setTimeout(resolve, 10));
return c.text('slug');
});
Requesting either /a
or /b
results in slug
being returned. Would be great to see this fixed so that there is a deterministic priority for route matching that is consistent.
Issue Analytics
- State:
- Created a year ago
- Comments:7
Top Results From Across the Web
Why Expres Async Errors send different result as expected
According to the document, if I create an error, express-async-errors has to handle this without crashing the application. My question is what I ......
Read more >Open handle keeps Jest from exiting ( TCPSERVERWRAP)
The server doesn't seem to be closing properly and you will get port collisions when trying to start the server in the different...
Read more >Using async routes with Express
By composing your Express routes with a simple wrapper, I show how you can take full advantage of async / await very easily....
Read more >Routing in Next.js – How to Set Up Dynamic ...
In this tutorial, you'll learn how to set up dynamic routing in Next.js. You'll also learn about pre-rendering and why it's important.
Read more >A Guide to Error Handling in Express.js
Error handling often doesn't get the attention it deserves. Mishandled errors can lead to a bad UX and negatively affect your business.
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
Just bumped and can confirm this is now behaving in a far more intuitive way to me (first handler that returns stops the chain)! Tyvm!
Hi @MattIPv4
Actually, the behavior in that both handlers are invoked is expected. So,
That is not wrong. Because all handlers are treated as Middleware. Every handler are called, and only one of the Response returned from the handlers will be used for the end-user.
It’s in the specifications.
BUT, I notice that this design is not good. In this case, only one handler should be processed, console.log should emit only
a
.I’ll consider it. Thank you!