feat: add --url-prefix flag for reverse proxy subpath support#309
feat: add --url-prefix flag for reverse proxy subpath support#309
Conversation
Allow the server to run behind a reverse proxy at a subpath (e.g., --url-prefix "/cook" serves all routes under /cook/). Uses Axum's Router::nest() for clean route mounting and NormalizePath middleware to handle trailing slashes. All templates, fetch calls, navigation links, and static asset URLs respect the configured prefix. Closes #300
PR Review: feat: add --url-prefix flag for reverse proxy subpath supportOverall this is a well-structured feature with thorough coverage across templates, JS, and the Axum routing layer. The approach of using Correctness
<script>window.__PREFIX__ = "{{ prefix }}";</script>Askama HTML-escapes values by default ( Fix: use the <script>window.__PREFIX__ = {{ prefix|json|safe }};</script>Behavioral Change
let app = tower_http::normalize_path::NormalizePath::trim_trailing_slash(app);This silently changes behavior when running without RobustnessValidation could be stricter in Minor Nits
OverallThe implementation is comprehensive and well thought out. The |
|
This will also help with this #186 |
Address PR review feedback: - Use |json|safe filter for window.__PREFIX__ to avoid HTML entity encoding issues in JS context - Validate URL prefix contains only safe URL path characters (alphanumeric, /, -, _, .)
PR Review: feat: add --url-prefix flag for reverse proxy subpath supportOverall this is a well-structured, useful feature. The implementation is thorough — all templates, JS fetch calls, and keyboard shortcuts have been updated consistently. CorrectnessInput validation is solid. The allowlist (alphanumeric, slash, dash, underscore, dot) covers legitimate subpaths and excludes characters that could cause issues in CSS selectors, redirects, or template injection.
Redirect fix for Potential IssuesEdge case: After
let app = tower_http::normalize_path::NormalizePath::trim_trailing_slash(app);This wraps every request unconditionally. For users not using Cookie path scoping in The cookie is set with Minor Notes
Summary
The single-slash edge case and the unconditional |
Summary
--url-prefixCLI flag tocook serverfor running behind a reverse proxy at a subpath (e.g.,cook server --url-prefix "/cook")Router::nest()for route mounting andNormalizePathmiddleware for trailing slash handlingwindow.__PREFIX__JS globalTest plan
cargo fmt— passescargo clippy— passescargo test— passescook server --url-prefix "/cook" ./seedserves UI at/cook//cook/and/cookboth return 200/returns 404 when prefix is set--url-prefix, server works as before at root/Closes #300