Add run-scoped public base URLs - #60
Merged
Merged
Conversation
One Billtap server shared by several proxied CI stacks could only generate absolute URLs (checkout session.url, billing portal URLs) against the single global BILLTAP_PUBLIC_BASE_URL, so hosted checkout redirects pointed at a port nobody listens on in multi-job CI. Each run can now pin its own browser-facing base through POST /runs/<runId>/v1/config (public_base_url, optional public_base_path). Absolute URLs resolve their base in order: the run config, an X-Billtap-Public-Base-Url request header, the forwarded proxy origin (X-Forwarded-Proto/Host/Prefix) for run-scoped requests, and finally the global base or request host, keeping the default run behaviour unchanged. The setting lives in memory with the run's API handler and is dropped with run deletion. Caller-provided success_url/cancel_url values stay untouched. 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.
Summary
One Billtap server shared by several proxied CI stacks could only generate absolute URLs (checkout
session.url, billing portal URLs) against the single globalBILLTAP_PUBLIC_BASE_URL. In multi-job CI each stack has its own nginx origin (e.g.https://localhost:19029/billtap), so hosted checkout redirects pointed athttps://localhost:8080where nothing listens —ERR_CONNECTION_REFUSEDand 24 cascading checkout/lifecycle test failures.Each run can now pin its own browser-facing base:
Absolute URLs generated under that run resolve their base in order:
public_base_url(+ optionalpublic_base_path)X-Billtap-Public-Base-Urlrequest headerX-Forwarded-Proto/Host/Prefix) for run-scoped requestsBILLTAP_PUBLIC_BASE_URL, then the request host — the previous behaviour, so the default run and single-stack setups are unchangedThe setting lives in memory with the run's per-run API handler (same lifetime as idempotency keys) and is dropped on run deletion.
GET/DELETE /runs/<runId>/v1/configinspect and clear it; the first request lazily creates the run, so a seed container can configure it before seeding. Caller-providedsuccess_url/cancel_urlvalues are never rewritten.Verification
go test ./...passes; all pre-existing tests pass unchanged (global-env fallback intact)run-avsrun-bvs unconfigured run vs default run), hosted-page session refetch sees the run base, run cleanup drops the config, forwarded origin beats the global base only for run-scoped requests, run config beats the forwarded origin/api/configalias), validation rejects non-http(s)/query/credential bases andpublic_base_pathwithoutpublic_base_url, header override works and loses to run config,success_url/cancel_urluntouchedOpen risks
🤖 Generated with Claude Code