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

Ability to proxy requests when serving with trunk serve #29

Closed
hamza1311 opened this issue Aug 31, 2020 · 8 comments · Fixed by #52
Closed

Ability to proxy requests when serving with trunk serve #29

hamza1311 opened this issue Aug 31, 2020 · 8 comments · Fixed by #52

Comments

@hamza1311
Copy link
Contributor

Currently, the development server spawned with trunk serve doesn't allow proxying requests. This renders it mostly useless as API calls to backend can't be made from the app served by the development server.

@MartinKavik
Copy link
Contributor

Related issue in Seeder: (see point 3.) MartinKavik/seeder#1

Personally, I run front-end and back-end on different domains and ports so I don't need it. However I can imagine it's useful e.g. for server dashboards.

@thedodd
Copy link
Member

thedodd commented Aug 31, 2020

renders it mostly useless

😂 lolz

Ok, feature request to support proxying requests to a backend, probably based on URI prefix (eg, /api/).

(edit: I suggest this in case you need an immediate solution) BTW, I'm not sure how much experience you have on this front, but there are actually lots of other ways solve this problem, especially given the fact that when you ship an application to a production environment, you will not (you should not) be using Trunk as the web server.

  • if you are using a docker based environment, you can just launch an nginx/traefik or some other simple web server to handle the request, and then do the proxying for you. It can split the traffic sending /api/ traffic to your API, and everything else can be sent over to the Trunk dev server.
  • if you are using Kubernetes, and perhaps you have a local kind cluster, you can just use K8s ingresses.

There are other simple patterns as well which are designed for development environments (docker-compose comes to mind), but which closely mirror a production environment.


All that said, adding a proxy to Trunk is a good idea. I'll get this prioritized soon.

@MartinKavik
Copy link
Contributor

My experience from Seed community

  • Many beginners want to fight with two "enemies" at once - backend and frontend. I don't know the reason, maybe there are used to write PHP / NodeJS / Django servers and splitting frontend and backend feels unnatural to them. Or maybe there are many Rust tutorials with servers so it looks like a good start, who knows. Beginners don't use K8s or Traefik.

  • Another group are veterans who want one server, one favorite database (Postgre/MySQL) and nothing more - the beauty of simplicity. UI is just a part of the server in their world.

@thedodd
Copy link
Member

thedodd commented Aug 31, 2020

That's well said. I agree. Beginners would definitely be overwhelmed at having to setup K8s ingresses or Traefik/nginx &c. I definitely don't want to recommend anything like that as "the way" to work with Trunk.

Definitely going to setup some proxy functionality.

I suppose, in the name of due diligence, what do you all (@MartinKavik && @hamza1311, and anyone else of course) see as being fundamentally need for this?

  • being able to simply declare a URI prefix, like /api/ and then a target backend, should do the trick in most cases. Transparent proxy.

Anything else which you think is needed here?

@MartinKavik
Copy link
Contributor

Anything else which you think is needed here?

  • Some user projects/servers serve the FE app from the root (/) and API endpoints are on /api/*. (Ideal case)
  • Other ones serve API endpoints on / and FE is served from /ui/. (Backend-first approach, UI is basically a nice-to-have)
  • 3rd option: Everything is on /. FE apps have to use hash routing to prevent conflicts. (Often modernized legacy apps.)

Note: Fetch and SSE should be relatively easy to pass through proxy, however I would be careful with non-HTTP protocols like WebSockets.

@Benjozork
Copy link

Many beginners want to fight with two "enemies" at once - backend and frontend. I don't know the reason, maybe there are used to write PHP / NodeJS / Django servers and splitting frontend and backend feels unnatural to them. Or maybe there are many Rust tutorials with servers so it looks like a good start, who knows. Beginners don't use K8s or Traefik.

People also sometimes run a single instance of their API server and don't want to setup K8s of all things on their workstation for something as simple as an API proxy.

@thedodd
Copy link
Member

thedodd commented Sep 4, 2020

@hamza1311 btw, I meant to ask you this earlier, but are you interested in contributing the code for this? I am about 3 days or so out from being able to switch gears over to the next milestone for trunk, and anyone willing to contribute would be greatly appreciated. No pressure, for sure. But I figured I would ask you and let you know that your code is WELCOME! :)

Just let me know. If not, I should be able to get around to it here quite soon. Cheers!

@thedodd thedodd mentioned this issue Sep 4, 2020
10 tasks
@hamza1311
Copy link
Contributor Author

@thedodd Its not like I don't want to. I don't think I have the knowledge to work on it (I'm willing to learn if you want to help out) or (in the near future) much time to work on it. If that's fine with you, then sure, it's worth a shot

thedodd added a commit that referenced this issue Sep 23, 2020
Implementation is complete and working quite nicely. Support for
multiple proxies when configured from Trunk.toml.

closes #29
related to #31
closes #33
thedodd added a commit that referenced this issue Sep 23, 2020
Implementation is complete and working quite nicely. Support for
multiple proxies when configured from Trunk.toml.

closes #29
related to #31
closes #33
@thedodd thedodd mentioned this issue Sep 23, 2020
1 task
thedodd added a commit that referenced this issue Sep 23, 2020
Implementation is complete and working quite nicely. Support for
multiple proxies when configured from Trunk.toml.

Update CHANGELOG describing changes.

Update README with docs on how the proxy system works.

closes #29
related to #31
closes #33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants