serve-handler
serve-handler copied to clipboard
Support for rewriting to external URLs
Would be great to have proxy support for external APIs in this microservice world. This would also alleviate the pain of using CORs. Also in relation to issue #28
{
"proxy": [
{ "path": "api/**", "destination": "https://xxx.api/" }
]
}
This is super interesting, thanks for proposing it. The only caveat is that the space of possible configuration options for such a feature is very broad.
cc @simonedavico
Maybe we could look at how others do it to be sure of taking into account every option? As I mentioned in #28, light-server offers a similar feature :)
This all sounds great. However, we don't have an internal need for this.
So any help would be greatly appreciated! ☺️
It'd be great to see this feature indeed, especially configurable inside serve
as a CLI argument.
Meanwhile, my workaround is to use http-server
:
npm install --global http-server
http-server path/to/web --port 5000 --proxy https://example.com/
This is how I could proxy http://localhost:5000/api/call
to https://example.com/api/call
.
@leo, any comment about @nathancahill PR?
@JounQin I'm not investing more time until I hear back from the maintainers that they are interested (in which case this PR can be finished) or not interested (in which case the feature will be available in serve-proxied on npm).
https://github.com/zeit/serve-handler/pull/75
I need this as well. For my use case I'm emulating locally my server's proxy settings. Hoping something like this would work:
"rewrites": [
{ "source": "/game/main", "destination": "http://localhost:9000/main"}
]
Any updates? this pr #75 is waiting for approvals
I was using serve for my SPA until I couldn't anymore because I need to proxy to API server. I found that local-web-server seems to support a lot of scenarios and did the trick for me.
Example command:
ws --port 5000 --directory dist --spa app.html --rewrite "/api/(.*) -> http://localhost:3000/$1"
Opens local server on port 5000, serves the dist
directory, uses app.html
as the SPA index, and rewrites requests to /api/$1
as http://localhost:3000/$1
I need this feature also.
shameless self-promotion alert:
this feature is available in my @warren-bank/serve
fork of serve
notes about using redirect rules:
- require an
engine
attribute..
which permits you to choose which methodology/library is used to:- match the url pathname against a pattern
- replace capture groups
- an optional boolean
proxy
attribute can be used to:- download from an external url
- pipe the response back to the client
What date is today ? Why is this issue still open ?