Multiple Middleware on Route Hangs
See original GitHub issueHey @kartikk221!
I rolled out my new micro services backed by hyper-express
and our recent changes and I noticed a bug. I’m trying to track it down, but I might need to tag you in as you are more familiar with this change.
When you define middleware on a specific route, it seems like every other request hangs and eventually fails. Here is a quick and easy reproduction. We should add this to the tests.
import {
Server,
type Request,
type Response,
type MiddlewareNext
} from 'hyper-express'
const app = new Server()
app.post(
'/echo',
async (req: Request, res: Response, next: MiddlewareNext) => {
req.body = await req.json()
next()
},
(req: Request, res: Response, next: MiddlewareNext) => {
res.locals.data = req.body
next()
},
(req: Request, res: Response) => {
res.status(200).json(res.locals.data)
}
)
app.listen(3000)
Then if you use Postman to POST
to localhost:3000/echo
with a request body:
{ "foo": "bar" }
Every other request hangs. Oddly this doesn’t happen when you curl
which leads me to believe that the socket isn’t being closed on the server side.
Any insight?
Issue Analytics
- State:
- Created a year ago
- Comments:35 (34 by maintainers)
Top Results From Across the Web
Laravel Multiple Middleware cause redirect loop - php
I have a middleware group of auth inside that i want to apply another middleware to one specific route in that view that...
Read more >Using middleware - Express.js
Route handlers enable you to define multiple routes for a path. The example below defines two routes for GET requests to the /user/:id...
Read more >Complete Guide to Express Middleware - Reflectoring
Our route with multiple middleware functions attached will look like ... middleware does not call the next() function and will simply hang.
Read more >How to assign multiple middlewares to a single route in Laravel
In some cases, you'll need to bunch multiple middlewares under a single key to send the assignment to a simple route. You can...
Read more >The What, When, Why And How Of Next.js' New Middleware ...
js' API routes were designed to be hosted on a single node server hosted in one place, whilst Middleware functions are designed 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
We should definitely do that as well. Im sure @alexhultman would appreciate it.
I’m working on a mac at the moment which is also unix. I will try to fix it, in the mean time can you run that script locally and hit it with postman?