Error occurred while trying to proxy request on Garden v0.12.50. #3667
Description
Bug
Current Behavior
Proxying a network request through a port forward created by Garden has been reported to fail with the following error after we upgraded to Node 18:
[HPM] Error occurred while trying to proxy request *** from localhost:XXXX to localhost:XXXX (ECONNREFUSED)
This seems to happen when the client sending the network request uses Node's http-proxy-middleware
and the target is localhost. Something like:
import { createProxyMiddleware } from "http-proxy-middleware"
const proxy = createProxyMiddlewareI({
target: "localhost:8080" // <--- Target is localhost
})
Expected behavior
I would expect things to work as before, but maybe this is an issue in Node 18. Here's an SO thread that looks relevant and the suggestion is to use 127.0.0.1
instead of localhost
.
So perhaps this is something that needs be handled by the user in the createProxyMiddleware
function as opposed to by Garden.
Workaround
First, set the GARDEN_PROXY_DEFAULT_ADDRESS
environment variable to 127.0.0.1. E.g.:
GARDEN_PROXY_DEFAULT_ADDRESS=127.0.0.1 garden deploy --dev
Then make sure to use 127.0.0.1
as opposed to localhost
in the createProxyMiddleware
function as suggested on StackOveflow.
Your environment
- OS: macOS
garden version
0.12.50.