Self-Hosted Proxy
Overview
setProxyURL routes the core SDK’s edge-function calls — offerings, purchases, customer info, attribution — through a reverse proxy you control. This is useful for:
- Regulatory environments that require all third-party traffic to leave through your edge.
- Adding extra observability (request logging, request signing, WAF rules).
- Regional failover and traffic shaping.
- Pinning to a vanity domain so SDK traffic appears under your own DNS.
It does not route everything, and the gaps matter if you are proxying to satisfy a regulator. On Android the billdog-auth module carries its own base URL and never reads the proxy setting; on both platforms a failed core call can be retried against a direct host; and social sign-in reaches the identity provider itself. Read Authentication traffic and the fallback note under Endpoint resolution before you treat the proxy as a complete egress boundary.
Setting the proxy URL
Set the proxy before calling configure() so the very first request uses it. The setter is idempotent and persists for the lifetime of the SDK process.
iOS
import BillDogFull
// Set first, then configure
BillDog.shared.setProxyURL("https://billdog-edge.example.com")
BillDog.shared.configure(config: BillDogConfig(apiKey: "YOUR_API_KEY"))
// Clear to fall back to the default BillDog endpoint
BillDog.shared.setProxyURL(nil)Android
import io.billdog.core.BillDog
import io.billdog.core.BillDogConfig
// Set first, then configure
BillDogConfig.setProxyURL("https://billdog-edge.example.com")
BillDog.configure(applicationContext, apiKey = "YOUR_API_KEY")
// Read back the active proxy
val active: String? = BillDogConfig.getProxyURL()
// Clear to fall back to the default
BillDogConfig.setProxyURL(null)Endpoint resolution
The two platforms compose the URL differently, and one proxy string will not serve both. Android uses the value verbatim — <proxy>/<function-name>. iOS appends the API version — <proxy>/v1/<function-name>. With no proxy set both resolve to https://api.billdog.io/v1. Trailing slashes are trimmed from whatever you pass.
To land on the same path from both, carry the version yourself on Android and leave it off on iOS: "https://edge.example.com/v1" on Android, "https://edge.example.com" on iOS. All other request shape — headers, body, auth — is unchanged.
The proxy is not an absolute egress boundary. When a core edge-function call answers 502, 503 or 504, or the host is unreachable, both SDKs retry it once against https://direct.billdog.io/functions/v1/<function-name>. That retry is not suppressed when a proxy is set, so an outage at your own edge sends the retry straight to BillDog. If your obligation is that nothing may leave except through your infrastructure, this is a path you have to account for.
Authentication traffic
Auth is not symmetric across the two platforms, so a proxy that is correct for purchases can still leave every sign-in going straight to BillDog.
iOS — already covered
BillDogAuth on iOS has no transport of its own. The runtime injects the shared core API client after configure() and every auth call goes through it, so setProxyURL already covers sign-up, sign-in, MFA, passkeys, organizations, token refresh and revocation. There is nothing extra to set. That path also has no direct.billdog.io fallback, so an auth request never leaves the proxy on an error.
Android — needs its own base URL
BillDogAuth on Android is a separate module with its own HTTP path. It takes a baseUrl at configure time and posts to <baseUrl>/<function-name>; it never reads BillDogConfig.getProxyURL(). Setting the proxy and leaving baseUrl alone leaves all auth traffic — passkeys and organizations included, since they share this path — going to whatever host you passed it.
import io.billdog.auth.BillDogAuth
import io.billdog.core.BillDog
import io.billdog.core.BillDogConfig
// Core: the proxy value is used verbatim, so carry the /v1 yourself.
BillDogConfig.setProxyURL("https://billdog-edge.example.com/v1")
BillDog.configure(applicationContext, apiKey = "YOUR_API_KEY")
// Auth: a separate module that reads none of the above. Give it the same
// base URL, or every sign-in request goes wherever this points instead.
BillDogAuth.configure(
context = applicationContext,
apiKey = "YOUR_API_KEY",
baseUrl = "https://billdog-edge.example.com/v1",
)What the proxy has to carry
The auth module calls these edge functions and no others: auth-sign-up, auth-attempt, auth-prepare, auth-token, auth-revoke, auth-org and auth-passkey. Social sign-in adds auth-oauth-verify, which lives in the core module and does follow the proxy on both platforms.
Forward the auth headers untouched. Every SDK sends the project key as X-BillDog-API-Key, and once someone is signed in every SDK call carries the session as X-BillDog-Session. Strip neither; an edge that drops X-BillDog-API-Key breaks every call.
Size the refresh load before you put a per-request-priced edge in front of it. A session token lasts 90 seconds and both SDKs schedule their refresh 20 seconds before expiry, so each signed-in app sends an auth-token request through your proxy roughly every 70 seconds for as long as the process is alive and holding a session.
Two things stay outside the proxy in every configuration: the identity provider itself — Android opens appleid.apple.com for Apple and runs Google Sign-In through Play services, iOS calls graph.facebook.com to verify a Facebook token — and nothing you configure here redirects them. Only the exchange that follows, auth-oauth-verify, is yours to route.
The auth model itself — sessions, entitlements carried in the token, organizations, verifying tokens on your own server — is documented under Authentication. This page only covers where the packets go.
Reference proxy (Cloudflare Worker)
export default {
async fetch(req: Request, env: Env) {
const url = new URL(req.url);
// Strip your edge prefix and forward to BillDog Supabase project.
const upstream = new URL(url.pathname + url.search, env.BILLDOG_BASE_URL);
const headers = new Headers(req.headers);
headers.set("host", new URL(env.BILLDOG_BASE_URL).host);
headers.set("x-forwarded-for", req.headers.get("cf-connecting-ip") ?? "");
return fetch(upstream.toString(), {
method: req.method,
headers,
body: req.body,
});
},
};Use whatever stack you prefer (Cloudflare Workers, AWS CloudFront + Lambda@Edge, Fastly, NGINX, Envoy). The only requirement is transparent forwarding of method, headers and body.
Related
Was this page helpful?
Or rate this page: