Repository navigation
feat(server): --proxy-strips-prefix for proxies that remove --url-prefix - #773
Merged
Merged
Conversation
--url-prefix both builds every URL under the prefix and moves every route under it. Home Assistant ingress, Traefik's StripPrefix and nginx's `proxy_pass http://…/;` forward requests without the prefix, so the routes 404 there, while leaving --url-prefix out sends the browser to the proxy's root for static files, links and API calls. --proxy-strips-prefix (requires --url-prefix) keeps routes at / and leaves everything browser-facing (links, redirects, cookie paths, feeds) on the prefix. The startup line and --open use the unprefixed address, where the server answers. Also lists --url-prefix in the docs' options table, which it was missing from. Closes cooklang#772 Co-Authored-By: Claude Opus 5.5 <[email protected]>
LeMyst
marked this pull request as ready for review
October 20, 2026 20:37
Collaborator
Author
|
Tested on Home Asssistant, no issue |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #772.
What
--url-prefix /cookdoes two things: every URL the server sends starts with/cook, and every route moves under/cook. Proxies that strip the prefix before forwarding (Home Assistant ingress, TraefikStripPrefix, nginxproxy_pass http://…/;) need the first without the second. Without it, either the routes 404 or the page's CSS, links and API calls go to the proxy's root.--proxy-strips-prefix(requires--url-prefix):Router::new().nest(prefix, inner), so routes stay at/;url_prefixas before: template links,PREFIXin page scripts, sign-in redirects, the session and feature cookie paths, feeds, image URLs;--open, since that is where the server answers. A second line names the prefix links use.A Home Assistant add-on would run:
cook server /recipes --host --port 8099 \ --url-prefix "$(bashio::addon.ingress_entry)" --proxy-strips-prefix \ --cors-origin http://homeassistant.local:8123Docs
docs/server.md:--url-prefixwas missing from the Options table. It is listed now along with the new flag, two examples (proxy keeps or strips the prefix), and a short "Behind a proxy that strips the prefix" section covering Home Assistant. That section points out that saving from the web UI still needs Home Assistant's address in--cors-origin, as with any proxy that rewritesHost.Tests
server_auth_test::a_prefix_stripped_by_the_proxy_is_kept_in_links_only:/is 200 and links/cook/static/favicon.ico;/static/favicon.icois 200 and/cook/static/favicon.icois 404;/edit/…redirects to/cook/login?next=…; sign-in setsPath=/cook;and redirects to/cook/; a save works.try_startprobes/rather than the prefix when the flag is given.cook server ./seed --url-prefix /api/hassio_ingress/abc --proxy-strips-prefixbehind nginxlocation /api/hassio_ingress/abc/ { proxy_pass http://127.0.0.1:18099/; }. Every link in the home page carries the prefix, and CSS, favicon, a recipe, a directory,/api/recipesand preferences are all 200 through the proxy.--proxy-strips-prefixwithout--url-prefixis refused by clap.🤖 Generated with Claude Code