Skip to content

Add support for kamal-proxy's path-prefix #1551

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ACPK
Copy link

@ACPK ACPK commented May 13, 2025

This PR introduces support for kamal-proxy's new path-based routing feature. For applications that split their traffic to different services based on the request path, you can use path-based routing to mount services under different path prefixes.

Begin by deploying the primary app that doesn’t require a path_prefix. Once that’s live, deploy your secondary app with the same host and the path_prefix feature.

Example Usage

# config/deploy.yml
...
servers:
  web:
    - 192.168.0.1

proxy:
  # Don't include ssl (TLS) options
  hosts:
    - callred.com
  path_prefix: '/api'
  # strip_path_prefix: true
...

NOTE: SSL options (e.g., ssl: true) should be set in the proxy for the app without a path_prefix, so the app above uses SSL by inheritance. Repeating the SSL settings here will cause the deploy to fail with a TLS error in the console.

With the above configuration, all incoming requests to https://callred.com/api/* will be routed to your service. By default, the path prefix will be stripped from the request before it is forwarded upstream. So in the example above, a request to /api/users/123 will be forwarded to the secondary app as /users/123. To instead forward the request with the original path (including the prefix), set: strip_path_prefix: true

Testing until added to main branch

For testing, I used the following setup in my Gemfile:

gem 'kamal', require: false, git: 'https://github.com/acpk/kamal.git', branch: 'kamal-proxy-path-prefix'

Deployment was performed with:

bundle exec kamal deploy

@ACPK ACPK changed the title Add support for path-prefix in Kamal proxy configuration Add support for kamal-proxy's path-prefix May 14, 2025
Copy link

@brgmn brgmn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some small newline fixes. The rest looks fine! Thanks for your integration work! Looking forward to being able to use path_prefix natively in kamal!

#
# For applications that split their traffic to different services based on the request path,
# you can use path-based routing to mount services under different path prefixes.
path_prefix: '/api'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something seems to be wrong with newlines here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ACPK Sorry. My fault. I just didn't understand the markdown logic. After looking at it again everything seems to be fine.

@ACPK ACPK requested a review from brgmn May 15, 2025 18:29
@shiny
Copy link

shiny commented May 26, 2025

I was wondering if there's any update on merging the PR?

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 this pull request may close these issues.

3 participants