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

Unable to proxy over https with domain that points to localhost #865

Closed TrevorBurnham closed 1 year ago

TrevorBurnham commented 1 year ago

Checks

Describe the bug (be clear and concise)

When running a local service over HTTPS, attempting to use a domain that resolves to 127.0.0.1 does not work.

Step-by-step reproduction instructions

1. Run a local service over HTTPS on port 8443.
2. Try modifying `examples/express/index.js` to use this config:

    createProxyMiddleware({
      target: 'https://xyz.localhost.me:8443',
      changeOrigin: true,
      secure: false,
    });

3. Run the example. This will yield `Error occurred while proxying request localhost:3000/ to http://xyz.localhost.me:3000/users [ENOTFOUND]`.

Expected behavior (be clear and concise)

Specifying the target with 127.0.0.1 instead of the domain causes the request to be proxied successfully:

createProxyMiddleware({
  target: 'https://127.0.0.1:8443',
  changeOrigin: true,
  secure: false,
});

I would expect the behavior with the domain to be the same.

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

I ran into this behavior when trying to use webpack-dev-server, but was able to replicate with the `http-proxy-middleware@3.0.0-beta.0` build in isolation.

What http-proxy-middleware configuration are you using?

N/A

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

macOS 12.6.2 and Node v18.12.1

Additional context (optional)

I'd thought this might be related to https://github.com/chimurai/http-proxy-middleware/issues/705, but I got the same behavior with both Node 14 and Node 18.