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

Removes port from target #985

Closed Netail closed 2 months ago

Netail commented 2 months ago

Checks

Describe the bug (be clear and concise)

When a target with a port is given, it gets proxied to the domain without port. E.g. when using http://127.0.0.1:3001 as a target, it will proxy to http://127.0.0.1

Step-by-step reproduction instructions

1. Set target to http://127.0.0.1:3001
2. Use the proxy 
3. Redirects to the url without the port

Expected behavior (be clear and concise)

Go to the correct port

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

- "_project_#custom-proxy" depends on it
   - Hoisted from "_project_#custom-proxy#http-proxy-middleware"

What http-proxy-middleware configuration are you using?

3.0.0 - createProxyMiddleware()

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

MacOS 14.4.1 - Node v20.8.1

Additional context (optional)

No response

chimurai commented 2 months ago

Can you share your server + proxy configuration? Even better if can provide a reproducible example

Netail commented 2 months ago

Can you share your server + proxy configuration? Even better if can provide a reproducible example

Seems to be only the logging; https://codesandbox.io/p/devbox/gracious-lamport-jfds4x

If you visit the /api or /web path, you see it excludes the port in the logging

max-holland commented 2 months ago

@Netail Yeah, looks like it is just the logging. Initially I thought I had an issue with the proxy but that seems to be working as intended.

Netail commented 2 months ago

It also automatically adds a trailing slash to the target which could trigger an infinite loop when the web server has a redirect to the non-trailing slash path

chimurai commented 2 months ago

Thanks for reporting and the reproduction. Merged a fix.


Trailing slash is added by the http-proxy lib. Should be fixed upstream.

chimurai commented 2 months ago

published fix for port issue in 3.0.1-beta.0

Netail commented 2 months ago

Thanks for reporting and the reproduction. Merged a fix.


Trailing slash is added by the http-proxy lib. Should be fixed upstream.

Will you make a ticket there or shall I?

chimurai commented 2 months ago

Feel free to create a ticket 👍

Netail commented 2 months ago

Feel free to create a ticket 👍

Mhm I doubt it will be picked up, they haven't updated that library for over 4 years now, same for all the security issues