feat: support serving Ratel under a URL prefix (-url-prefix)#422
Open
shaunpatterson wants to merge 1 commit into
Open
feat: support serving Ratel under a URL prefix (-url-prefix)#422shaunpatterson wants to merge 1 commit into
shaunpatterson wants to merge 1 commit into
Conversation
Adds a -url-prefix flag (with RATEL_URL_PREFIX env fallback) to the Go server so Ratel can be hosted under a subpath behind reverse proxies, e.g. https://example.com/ratel/ (fixes dgraph-io#390). When a prefix is set: - all routes are served under the prefix via http.StripPrefix - the bare prefix redirects (301) to the prefix with a trailing slash - root-relative href/src URLs and the inline loader.js reference in the served index.html are rewritten to include the prefix - paths outside the prefix return 404 with a hint at the prefix With no prefix (the default) behavior is unchanged. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
What
Implements #390: serve Ratel under a URL prefix (e.g.
https://host/ratel/) behind reverse proxies.-url-prefixflag withRATEL_URL_PREFIXenv fallback (env used only when the flag is empty). Default empty = behavior unchanged.""/"/"→ no prefix); multi-segment prefixes (/a/b) work.http.StripPrefix; bare/ratel→ 301 to/ratel/(path-only redirect, proxy-safe); root-relativehref/srcattributes and the inlineinjectJs('/loader.js')in the served index.html are rewritten at startup (protocol-relative//cdn...URLs deliberately untouched); paths outside the prefix return 404 with a hint ("Ratel is served under /ratel/") rather than hijacking the root of a shared host.Testing
9 Go tests (httptest): prefix normalization table, HTML rewriting incl. the protocol-relative exclusion, no-prefix behavior unchanged (root + asset), prefixed index rewritten, bare-prefix redirect, outside-prefix 404s, embedded static assets resolving under the prefix. Asset tests pick a real name from bindata's
AssetNames()so they don't depend on build contents.Manually verified with the built binary:
-url-prefix /ratelserves/ratel/with rewritten asset URLs, redirects/ratel, 404s/, and the env-var fallback works. Docs added to INSTRUCTIONS.md alongside the existing TLS flags.Closes #390.
🤖 Generated with Claude Code