serve icon indicating copy to clipboard operation
serve copied to clipboard

Can't redirect to different port

Open jacobparis opened this issue 6 years ago • 4 comments

I am using the netlify-lambda package to serve my functions on port 9000. Using the redirects field in my configuration, I want to proxy the path that Netlify will host them at during local development.

Using the following serve.json file

{
    "redirects": [
        {
            "source": "/.netlify/functions/:path",
            "destination": "http://localhost:9000/:path",
            "type": 302
        }
    ]
}

I get the error

UnhandledPromiseRejectionWarning: TypeError: Expected "9000" to be a string

because the port designation :9000 is treated as a parameter instead. I tried replacing it with http://localhost%3A9000/:path, but the % is then encoded leaving me with %253A which does not solve the problem.

jacobparis avatar Sep 12 '19 01:09 jacobparis

This message doesn't help a lot, but apparently the maintainers forgot about this project, unfortunately.

Cornul11 avatar May 14 '20 10:05 Cornul11

Also experiencing this issue :(

bmitchinson avatar Mar 08 '21 22:03 bmitchinson

also having the same issue :(

alwyntan avatar Mar 26 '21 05:03 alwyntan

you should escape the colon before the port number with a backslash.. so path-to-regexp doesn't attempt to interpolate it as a named capture group.

ex: "destination": "http://localhost\\:9000/:path",

fwiw, one of the bugs in serve causes problems when a directory name includes a . character. I haven't looked at the code in a while, so I don't remember the particulars.. but there are occasions when such directories will be treated as a file.. because the name is assumed to contain a file extension.

warren-bank avatar Feb 10 '22 08:02 warren-bank