Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for rewriting to external URLs #30

Open
chiefjester opened this issue Jun 15, 2018 · 12 comments · May be fixed by #75
Open

Support for rewriting to external URLs #30

chiefjester opened this issue Jun 15, 2018 · 12 comments · May be fixed by #75
Labels
help wanted Extra attention is needed

Comments

@chiefjester
Copy link

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/" }
  ]
}
@rauchg
Copy link
Member

rauchg commented Jun 15, 2018

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.

@rauchg
Copy link
Member

rauchg commented Jun 15, 2018

cc @simonedavico

@simonedavico
Copy link

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 :)

@leo leo changed the title proposal: proxy for external api/urls Support for rewriting to external URLs Jun 15, 2018
@leo leo added the help wanted Extra attention is needed label Aug 21, 2018
@leo
Copy link
Contributor

leo commented Aug 21, 2018

This all sounds great. However, we don't have an internal need for this.

So any help would be greatly appreciated! ☺️

@kachkaev
Copy link
Contributor

kachkaev commented Oct 17, 2018

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.

@Toub
Copy link

Toub commented Sep 25, 2019

@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).

#75

@geddski
Copy link

geddski commented Nov 20, 2019

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"}
  ]

@FerLuisxd
Copy link

Any updates? this pr #75 is waiting for approvals

@valentinoli
Copy link

valentinoli commented Nov 5, 2020

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

@abronin
Copy link

abronin commented Jan 18, 2021

I need this feature also.

@warren-bank
Copy link

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

@kmsheng
Copy link

kmsheng commented Aug 18, 2023

What date is today ? Why is this issue still open ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.