From 1331e7b9c7c972c75011439650f002c7c05bc299 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 13 May 2025 19:31:54 -0400 Subject: [PATCH] Added path_prefix and strip_path_prefix --- lib/kamal/configuration/docs/proxy.yml | 11 +++++++++++ lib/kamal/configuration/proxy.rb | 2 ++ 2 files changed, 13 insertions(+) diff --git a/lib/kamal/configuration/docs/proxy.yml b/lib/kamal/configuration/docs/proxy.yml index 49c11ac8..9bd37034 100644 --- a/lib/kamal/configuration/docs/proxy.yml +++ b/lib/kamal/configuration/docs/proxy.yml @@ -74,6 +74,17 @@ proxy: # How long to wait for requests to complete before timing out, defaults to 30 seconds: response_timeout: 10 + # Path-based routing + # + # 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' + # 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 web-1 as /users/123. + # To instead forward the request with the original path (including the prefix), + # specify --strip-path-prefix=false + strip_path_prefix: false + # Healthcheck # # When deploying, the proxy will by default hit `/up` once every second until we hit diff --git a/lib/kamal/configuration/proxy.rb b/lib/kamal/configuration/proxy.rb index b5afbaae..2af2e71c 100644 --- a/lib/kamal/configuration/proxy.rb +++ b/lib/kamal/configuration/proxy.rb @@ -41,6 +41,8 @@ class Kamal::Configuration::Proxy "buffer-memory": proxy_config.dig("buffering", "memory"), "max-request-body": proxy_config.dig("buffering", "max_request_body"), "max-response-body": proxy_config.dig("buffering", "max_response_body"), + "path-prefix": proxy_config.dig("path_prefix"), + "strip-path-prefix": proxy_config.dig("strip_path_prefix"), "forward-headers": proxy_config.dig("forward_headers"), "tls-redirect": proxy_config.dig("ssl_redirect"), "log-request-header": proxy_config.dig("logging", "request_headers") || DEFAULT_LOG_REQUEST_HEADERS,