serve
serve copied to clipboard
Can't redirect to different port
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.
This message doesn't help a lot, but apparently the maintainers forgot about this project, unfortunately.
Also experiencing this issue :(
also having the same issue :(
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.