UNIFI_API_KEY, calls the UniFi API, and returns the upstream status response.
The proxy is intentionally narrow. It accepts only GET and OPTIONS, and only these paths:
/payment/merchant/session/:sessionIdbelow the configured proxy prefix, with a valid 64-character hexadecimal session ID; and/payment/onchain/receipt/:receiptIdbelow the configured proxy prefix, with a valid UniFi receipt ID.
Cloudflare Pages
Createfunctions/api/unifi/[[path]].ts:
UNIFI_API_KEY as an encrypted Cloudflare Pages secret. Do not add it as a public build-time
variable.
Any Fetch API-compatible server
Configuration
Most production merchants should use the defaults for
apiPrefix and UNIFI_API_BASE_URL.
The proxy forwards these allowlisted requests to the corresponding /v1/... UniFi API routes.
Cross-origin frontend
Same-origin requests need no extra CORS configuration. If the frontend and proxy deliberately use different origins, allow each literal browser origin:0.0.0.0 as browser origins, and do not use a wildcard for a
secret-bearing proxy.
Response behavior
- Valid status responses pass through with
Cache-Control: no-store. - The proxy removes
Set-Cookiefrom the upstream response. - Missing server configuration returns
500without revealing a key. - Disallowed routes return
404; unsupported methods return405. - An unreachable UniFi API returns
502. - CORS headers are emitted only for the request origin or an explicitly allowed origin.
Security checklist
- Keep
UNIFI_API_KEYin the runtimeβs encrypted secret store. - Search generated JavaScript, HTML, source maps, logs, and browser requests for accidental key exposure before launch.
- Keep the allowlist limited to the session lookup and single-receipt status routes.
- Add merchant-side monitoring and rate limits appropriate for checkout traffic.
- Reject status checks that are not associated with a known merchant order when your server owns that association.
- Log order IDs and session IDs as operational identifiers, but never log API keys or wallet signing material.