question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple Middleware on Route Hangs

See original GitHub issue

Hey @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:closed
  • Created a year ago
  • Comments:35 (34 by maintainers)

github_iconTop GitHub Comments

1reaction
SupremeTechnopriestcommented, Apr 28, 2022

We should definitely do that as well. Im sure @alexhultman would appreciate it.

1reaction
SupremeTechnopriestcommented, Apr 28, 2022

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found