chimurai / http-proxy-middleware

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

POST Timeout #872

Closed tapz closed 1 year ago

tapz commented 1 year ago

Checks

Describe the bug (be clear and concise)

The same url works with curl, but not with http-proxy-middleware. The Express is running in Heroku. CURL in my local mac (also tested with an Android app). Based on the target logs in AWS CloudWatch logs for the lambda function, the proxied request never reaches the destination.

curl -X POST https://mytarget.com/api/v1/a/b

Feb 6 23:57:11  [HPM] Router new target: https://mytarget.com -> "https://mytarget.com"
Feb 6 23:57:11  [HPM] POST /api/v1/a/b -> https://mytarget.com
Feb 6 23:57:38  [ERROR] <SB691916D483>  HTTP failed: Response timeout 
Feb 6 23:57:38  [ERROR] <SB691916D483>  Stack: ServiceUnavailableError: Response timeout
Feb 6 23:57:38      at IncomingMessage.<anonymous> (/app/node_modules/connect-timeout/index.js:84:8)
Feb 6 23:57:38      at IncomingMessage.emit (node:events:513:28)
Feb 6 23:57:38      at Timeout._onTimeout (/app/node_modules/connect-timeout/index.js:49:11)
Feb 6 23:57:38      at listOnTimeout (node:internal/timers:559:17)
Feb 6 23:57:38      at processTimers (node:internal/timers:502:7)

Step-by-step reproduction instructions

1. Call the api
2. Timeout

Expected behavior (be clear and concise)

No timeout

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

=> Found "http-proxy-middleware@2.0.6"
info Has been hoisted to "http-proxy-middleware"
info This module exists because it's specified in "dependencies".
info Disk size without dependencies: "184KB"
info Disk size with unique dependencies: "596KB"
info Disk size with transitive dependencies: "4.66MB"
info Number of shared dependencies: 10

What http-proxy-middleware configuration are you using?

router.use(
    '/api/v1',
    createProxyMiddleware({
      target: 'https://mytarget.com',
      router: () => 'https://mytarget.com',
      changeOrigin: true,
      logLevel: 'debug',
      logProvider: () => {
        return {
          log: console.log,
          debug: console.info,
          info: console.info,
          warn: console.warn,
          error: console.error,
        };
      },
    })
  );

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

```shell
Heroku (AWS)
Ubuntu 20.04
Node 18.13.0 (also tested with 16.x.x)

Additional context (optional)

No response

chimurai commented 1 year ago

Not clear from your example... I suspect you are also using the body-parser middleware. If so, try to configure body-parser after http-proxy-middleware

chimurai commented 1 year ago

dupe of https://github.com/chimurai/http-proxy-middleware/issues/40#issuecomment-163398924