Skip to content

feat(server): --proxy-strips-prefix for proxies that remove --url-prefix - #773

Merged
LeMyst merged 1 commit into
cooklang:mainfrom
LeMyst:feat/proxy-strips-prefix
Oct 22, 2026
Merged

LeMyst merged 1 commit into
cooklang:mainfrom
LeMyst:feat/proxy-strips-prefix

Conversation

@LeMyst

@LeMyst LeMyst commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator

Closes #772.

What

--url-prefix /cook does 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, Traefik StripPrefix, nginx proxy_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):

  • skips Router::new().nest(prefix, inner), so routes stay at /;
  • leaves everything browser-facing on url_prefix as before: template links, PREFIX in page scripts, sign-in redirects, the session and feature cookie paths, feeds, image URLs;
  • prints the unprefixed address in the startup line and opens it with --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:8123

Docs

docs/server.md: --url-prefix was 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 rewrites Host.

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.ico is 200 and /cook/static/favicon.ico is 404; /edit/… redirects to /cook/login?next=…; sign-in sets Path=/cook; and redirects to /cook/; a save works.
  • try_start probes / rather than the prefix when the flag is given.
  • Manual: cook server ./seed --url-prefix /api/hassio_ingress/abc --proxy-strips-prefix behind nginx location /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/recipes and preferences are all 200 through the proxy.
  • --proxy-strips-prefix without --url-prefix is refused by clap.

🤖 Generated with Claude Code

--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
LeMyst marked this pull request as ready for review October 20, 2026 20:37
@LeMyst

LeMyst commented Oct 22, 2026

Copy link
Copy Markdown
Collaborator Author

Tested on Home Asssistant, no issue

@LeMyst
LeMyst merged commit 5c63947 into cooklang:main Oct 22, 2026
6 checks passed
@LeMyst
LeMyst deleted the feat/proxy-strips-prefix branch October 22, 2026 11:47
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.

Server: serve at / while building links under --url-prefix (proxies that strip the prefix, e.g. Home Assistant ingress)

1 participant