chimurai / http-proxy-middleware

:zap: The one-liner node.js http-proxy middleware for connect, express, next.js and more
MIT License
10.6k stars 828 forks source link

TypeError: (options.buffer || req).pipe is not a function #973

Closed jaythakor-ai closed 3 months ago

jaythakor-ai commented 3 months ago

Checks

Describe the bug (be clear and concise)

I am using the uWebSockets-express in my application. I am trying to proxy my simple get request but facing the above error. This is working fine in the express app but not when using the uWebSockets-express.

Step-by-step reproduction instructions

1. Created the node app with the uWebSockets-express
2. create a simple get call
3. Proxy the get call to some other server.

Expected behavior (be clear and concise)

It should work the same as the node app

How is http-proxy-middleware used in your project?

Using it to proxy the incoming request to another server.

What http-proxy-middleware configuration are you using?

app.use((req, res, next) => {
  if (req.url.startsWith('/')) {
            createProxyMiddleware({ target: "http://localhost:3000" })(req, res, next);
        } else {
            next();
        }
//   next(); // Call the next middleware in the chain
});

What OS/version and node/version are you seeing the problem?

Ubunut 22.04 & node 18.17.0

Additional context (optional)

No response

chimurai commented 3 months ago

Sounds like a configuration issue

Not recommended to call createProxyMiddleware inside app.use This'll create a new proxy for every request...

This might cause the issue you are facing.

Example: https://github.com/chimurai/http-proxy-middleware/blob/master/README.md#express-server-example

Nothing I can't do without reproduction example Feel free to re-open if you can provide one.