chimurai / http-proxy-middleware

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

Fails to proxy from localhost to localhost #952

Open vadi2 opened 11 months ago

vadi2 commented 11 months ago

Checks

Describe the bug (be clear and concise)

Proxying from one localhost port to another localhost port doesn't seem to work.

Step-by-step reproduction instructions

app.use(
    "/api/organization/v1/organization",
    createProxyMiddleware({
      target: "http://localhost:8000",
      changeOrigin: true,
      pathRewrite: {
        "^/api/organization/v1/organization/": "/api/organization/v1/organization/",
      },
    })
  );

Results in:

[HPM] Error occurred while proxying request localhost:3000/api/organization/v1/organization/9db5e2af-81a1-476c-8ddb-45168e02fc6e to http://localhost:8000/ [ECONNREFUSED] (https://nodejs.org/api/errors.html#errors_common_system_errors)

Expected behavior (be clear and concise)

The request is proxied.

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

% yarn why http-proxy-middleware
yarn why v1.22.19
[1/4] 🤔  Why do we have the module "http-proxy-middleware"...?
[2/4] 🚚  Initialising dependency graph...
[3/4] 🔍  Finding dependency...
[4/4] 🚡  Calculating file sizes...
=> Found "http-proxy-middleware@2.0.6"
info Has been hoisted to "http-proxy-middleware"
info Reasons this module exists
   - Specified in "dependencies"
   - Hoisted from "react-scripts#webpack-dev-server#http-proxy-middleware"
info Disk size without dependencies: "156KB"
info Disk size with unique dependencies: "744KB"
info Disk size with transitive dependencies: "8.67MB"
info Number of shared dependencies: 34
✨  Done in 0.39s.

What http-proxy-middleware configuration are you using?

app.use(
    "/api/organization/v1/organization",
    createProxyMiddleware({
      target: "https://fe59-2a02-a210-22c3-ab80-b4a6-fcf4-5617-2ff.ngrok.io",
      changeOrigin: true,
      pathRewrite: {
        "^/api/organization/v1/organization/": "/api/organization/v1/organization/",
      },
    })
  );

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

MacOS 13.6

Additional context (optional)

No response

leolcao commented 11 months ago

We meet this issue also, try to set the target url with '0.0.0.0' or '127.0.0.1' instead of 'localhost'

vadi2 commented 11 months ago

That was it - thank you.