basecamp / kamal-proxy

Lightweight proxy server for Kamal
https://kamal-deploy.org/
MIT License
690 stars 24 forks source link

Add Support for Path-Based Routing in Kamal #48

Open jvkassi opened 2 weeks ago

jvkassi commented 2 weeks ago

Currently, Kamal only supports host-based routing, which limits its flexibility when managing requests on a single domain or multiple applications under the same host. To enhance its functionality and improve usability, I suggest implementing path-based routing for the following reasons:

With path-based routing, multiple services can be deployed under a single host (e.g., example.com/app1, example.com/app2), reducing the need for additional hostnames or subdomains. This is particularly beneficial when using wildcard SSL certificates or when managing applications within a single domain.

Path-based routing allows for the separation of different applications or services under distinct paths (e.g., /api, /admin). This simplifies management and reduces complexity, especially when dealing with microservices or multiple frontends that share a domain.

kevinmcconnell commented 2 weeks ago

@jvkassi yes, agreed. We've been talking about adding this, and I have a solution in mind that I'm starting to work on. My current thinking is we'll add a path prefix option that you can use when deploying, either in combination with host-based routing or on its own. If you specify a path prefix, then only requests that match the prefix will be routed to that service. That should be enough to have apps share a domain but split according to /api, /admin, /app, etc.

I expect to have something more concrete to try out for this soon.

nuschk commented 1 week ago

My usecase (with Kamal 1.9) is to have a CMS and an app server behind the same Traefik instance, on the same domain. What I do is route the root path (/) and all paths with a content prefix (/c/*), as well as some CMS related paths (/_next/* etc.) to the CMS, and have all other requests fall back to the app server.

I wonder how that would be able with your proposal. It would probably require either some sort of service priority (which is what Traefik offers) or some sort of negation ("not these paths"). And also, not just path prefixes, but also paths (a distinction Traefik makes as well).

Would be great if that would go into your consideration!