> ## Documentation Index
> Fetch the complete documentation index at: https://docs.y.uno/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Test in the sandbox first: base URL https://api-sandbox.y.uno (Test Mode in the Dashboard). Production is https://api.y.uno (Live Mode).
> Every API request needs the public-api-key and private-secret-key headers. Get them in the Dashboard at https://dashboard.y.uno/developers (Developers > Credentials); sandbox and production keys are different.
> Send an X-Idempotency-Key (a UUID) when creating payments, refunds and cancels, so retries do not create duplicates.
> Start with the Quickstart (https://docs.y.uno/docs/quickstart.md) and the agent guide (https://docs.y.uno/agents.md). To search these docs from a coding agent, connect the docs MCP server at https://docs.y.uno/mcp.

# White Label Proxy Server

> A local Express harness that loads the Yuno Web SDK from a non-Yuno origin to verify white-label paths.

> [!NOTE]
>
> **This page documents a legacy SDK.** Starting a new integration? Use the [Yuno SDK](https://docs.y.uno/docs/yuno-sdk/get-started.md). Already on a legacy SDK? Follow the [migration guide](https://docs.y.uno/docs/yuno-sdk/migration/overview.md).
>
> The new **Yuno SDK** (Web v2.x, iOS v3.x, Android v3.x, React Native v2.x) replaces the Full, Lite, Seamless, Render, Headless, and Secure Fields SDKs with one API across every platform. Legacy SDKs remain supported side by side during the transition and are scheduled for deprecation in **2027**. Contact your Account Manager for migration planning.

A small Express server that emulates a merchant's own origin (or sub-path) in front of the Yuno stack. It lets both white-label surfaces be exercised end-to-end from a **non-Yuno origin** before shipping a partner-hosted integration:

* **SDK white-label**: the Yuno Web SDK loaded from a foreign host, verifying the renamed globals, events, and DOM tokens.
* **Hosted checkout white-label (Payment Link)**: the `sdk-checkout` app (normally `checkout.<env>.y.uno`) fronted by the merchant origin/sub-path, so `checkout.y.uno/payment?session=…` can be mapped onto `their.host/<base-path>/payment?session=…`.

> [!TIP]
>
> This is a companion to the [White Label](https://docs.y.uno/docs/sdks/customization/web/white-label.md) page. Read it first for the SDK-side overrides this harness is built to verify.

## Why this server exists

The Yuno Web SDK historically ships with a `yuno-` prefixed surface: `window.Yuno`, the `yuno-sdk-ready` event, and `yuno-*` CSS classes and data attributes. The white-label release introduces a parallel surface:

| Legacy | White-label |
| :- | :- |
| `window.Yuno` | `window.SdkPayments` |
| `yuno-sdk-ready` event | `sdk-payments-ready` event |
| `yuno-*` DOM tokens | `sdk-payments-*` DOM tokens |

To verify the rename actually shipped, the SDK must be loaded from a host that is **not** `*.y.uno`. If it loads from a Yuno origin, branded leaks would slip through unnoticed. This server is the harness: it serves the SDK from `localhost:9090` (or any non-Yuno hostname you point it at) and forwards every request to the real Yuno upstreams transparently.

The same harness also fronts the **hosted Payment Link checkout**: it serves the `sdk-checkout` SPA routes from the proxy origin, rewrites the app's asset origin back onto itself, and forwards the checkout BFF and status WebSocket upstream. This lets the hosted checkout be white-labeled onto a merchant origin/sub-path without any `*.y.uno` request leaking from the page. See [Hosted checkout white-label (Payment Link)](#hosted-checkout-white-label-payment-link).

## How it works

```text theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
┌──────────────────┐     ┌────────────────────────────┐     ┌─────────────────────┐
│  Partner page    │───▶ │   white-label-proxy        │───▶ │ Yuno upstreams      │
│  (browser)       │     │   (Express :9090)          │     │  - checkout.*.y.uno │
│                  │ ◀───│                            │ ◀───│  - sdk-web.*.y.uno  │
│ <script src=     │     │   Routes by path:          │     │  - sdk-3ds.*.y.uno  │
│  localhost:9090/ │     │  /payment,/enroll → CHECKOUT│     │  - sdk-web-card.*   │
│  v1.7/main.js>   │     │  /checkout-bff/*  → BFF     │     │  - sdk.prod.y.uno   │
│   ─ or ─         │     │    /v1/*         → BACKEND  │     │  - icons.prod.y.uno │
│  /payment?       │     │    /v<n>/pages    → CARD    │     │  - <env>.y.uno (BFF)│
│  session=…       │     │    /challenge     → 3DS     │     │  - api[-env].y.uno  │
│                  │     │  /sdk-static-bundles-ms/*   │     │  - prod.y.uno       │
│                  │     │                → BUNDLES    │     │   (fonts, fraud JS) │
│                  │     │    /icons,/css    → STATIC  │     │                     │
│                  │     │    /flags,/*.png  → ICONS   │     │                     │
│                  │     │    else           → SDK     │     │                     │
└──────────────────┘     └────────────────────────────┘     └─────────────────────┘
```

Three invariants make the harness useful:

1. **The browser only ever talks to the proxy origin.** No `*.y.uno` request originates from the page itself; otherwise the SDK is not really being tested against a foreign host.
2. **All upstream domains are reachable from the proxy.** SDK assets, the card-form micro-app, the 3DS micro-app, the REST API, and the WebSocket service are all separate hostnames that must each be configurable.
3. **CORS is owned by the proxy, not the upstream.** Upstream CORS would respond with `api.y.uno` origins; the proxy strips those and writes its own, echoing the caller.

## Architecture

A single Node.js process built on three libraries:

* `express`: routing and middleware for HTTP.
* `node-fetch`: outbound HTTP to upstreams, for streaming bodies and header control.
* `http-proxy`: WebSocket upgrades, because Express middleware never sees `Upgrade` requests.

### Request lifecycle

0. **Base-path strip** runs before everything else, and only when `BASE_PATH` is set. It rewrites `req.url` / `req.originalUrl` to drop the configured sub-path so all downstream matching and forwarding sees root-relative paths. A no-op (not even registered) for a root mount. See [`BASE_PATH`: sub-path mounting](#base_path--sub-path-mounting).
1. **CORS middleware** runs next. It echoes the caller's `Origin`, handles `OPTIONS` preflight, and sets `Access-Control-Allow-Credentials: true`. The proxy is the CORS authority.
2. **Local routes** match before anything else: `/`, `/static/*`, `/whitelabel-info`. These never touch an upstream.
3. **Backend pass-through** matches `/v1/*` and `/v2/*` (the Yuno REST surface used by the SDK) and forwards via `node-fetch` to `BACKEND_URL`. Hop-by-hop headers are stripped; `access-control-*` headers from the upstream are dropped so they cannot override the proxy's own CORS. The browser `Cookie` header is also dropped on these forwards. The partner page's localhost cookies (session, analytics, URL-valued ones, …) don't belong on a cross-origin call to `api.y.uno` and can trip the upstream WAF with a `403`; the API authenticates via the public API key.
4. **Checkout BFF pass-through** matches `/checkout-bff/*` and forwards to `CHECKOUT_BFF_UPSTREAM`, sharing the same forwarder as the backend (body re-serialized, hop-by-hop and `access-control-*` and `Cookie` stripped). The `sdk-checkout` app calls its BFF through the white-labeled `apiUrl` (`host/<base-path>/checkout-bff/v1`), so after the base-path strip the proxy sees `/checkout-bff/*` (`GET /checkout-bff/v1/checkout-info/{session}`, `POST /checkout-bff/v1/checkout/payment`). See [Hosted checkout white-label (Payment Link)](#hosted-checkout-white-label-payment-link).
5. **Checkout SPA routes** match `/payment`, `/payment/status`, and `/enroll` (`GET`), registered before the SDK catch-all. Each fetches `CHECKOUT_UPSTREAM/index.html` and rewrites the app's absolute asset origin (`PUBLIC_URL`, e.g. `checkout.<env>.y.uno`) to `BASE_PATH`, so the CRA bundle, favicon, and manifest load back through the proxy instead of leaking to the Yuno host. react-router resolves the actual route client-side from `window.location`.
6. **SDK/asset catch-all** matches every remaining `GET`/`HEAD`. A small dispatcher (`pickSdkUpstream`) picks the right upstream based on path, checked top to bottom, each rule anchored at the start of the path (after the base path), so the checkout/3DS/card rules win first:

   * Checkout app assets: the CRA bundle (`/static/(js|css|media)/*`) and root public files (`/favicon.ico`, `/manifest.json`, `/robots.txt`, `/asset-manifest.json`) → `CHECKOUT_UPSTREAM`. Checked **first** so they don't fall through to the SDK icon upstream.
   * 3DS micro-app paths (`/challenge.html`, `/redirect.html`, `/session-id.html`, and `/assets/(challenge|redirect|session-id|validate-url)*`) → `SDK_3DS_UPSTREAM`.
   * Card micro-app paths (`/v<semver>/pages/*`, `/v<semver>/assets/*`) → `SDK_CARD_UPSTREAM`.
   * Static-bundles paths (`/sdk-static-bundles-ms/*`) → `SDK_STATIC_BUNDLES_UPSTREAM` (`prod.y.uno`). Since SDK 1.10.9 the SDK loads its font stylesheet from `prod.y.uno/sdk-static-bundles-ms/v1/static/css/…`, and the stylesheet loads its `woff2` files with relative `../fonts/` URLs under the same prefix. From SDK 1.11.16 the Forter script and the Riskified SRI beacon are also requested from this prefix on the white-label host (earlier releases request them straight from `prod.y.uno`, bypassing the proxy). Checked before the static rule, because its paths also contain `/static/css/`, `/static/js/` and `/fonts/`.
   * Static-asset paths (`/icons/*`, `/css/*`, `/brands/*`, `/c2p/*`, `/wallets/*`, `/fonts/*`) → `SDK_STATIC_UPSTREAM` (`sdk.prod.y.uno`).
   * Icon-asset paths (`/sdk-web/*`, `/flags/*`, and bare root brand images like `/Visa.png`, `/boleto_logosimbolo.png`) → `SDK_ICONS_UPSTREAM` (`icons.prod.y.uno`).
   * Everything else → `SDK_UPSTREAM`.

   The static / icons branches exist because the SDK used to load these straight from `icons.prod.y.uno` / `sdk.prod.y.uno`, bypassing the white-label host. Recent SDK builds host-swap them onto the proxy origin (path preserved), so the proxy must forward them back out to the CDNs by path prefix. `sdk.prod.y.uno` and `icons.prod.y.uno` are the same in every environment; `/sdk-static-bundles-ms/*` defaults to `prod.y.uno` (only the Riskified SRI beacon uses `staging.y.uno` outside production).
7. **WebSocket upgrades** are handled on the underlying `http.Server`, not Express. `/checkout-websocket-notification-ms/ws/{payment,enrollment}` → `BACKEND_WS_URL` (the hosted-checkout status stream); everything else follows the same SDK / card / 3DS split as HTTP.

### Version normalization

The main SDK bundle is versioned (`/v1.7.4/main.js`). Two complications:

* Partner pages may hardcode a version that the upstream no longer publishes.
* The "current" version drifts over time.

The proxy resolves the canonical version once at boot and rewrites every incoming `/v<x>/*` SDK request to that version before sending it upstream. Card-app and 3DS paths are **not** rewritten; they have their own publish cadences.

## Hosted checkout white-label (Payment Link)

A merchant white-labels Yuno's hosted checkout by mapping `checkout.<env>.y.uno/payment?session=…` onto their own `host/<BASE_PATH>/payment?session=…`. The harness emulates this locally with two upstreams: `CHECKOUT_UPSTREAM` (the `sdk-checkout` app shell) and `CHECKOUT_BFF_UPSTREAM` (the BFF it calls):

* **SPA routes**: `/payment`, `/payment/status`, and `/enroll` each fetch `CHECKOUT_UPSTREAM/index.html`. The served HTML's asset links are absolute (`PUBLIC_URL` = `checkout.<env>.y.uno`), so the proxy rewrites that origin to `BASE_PATH`, keeping the CRA bundle, favicon, and manifest on the proxy origin instead of leaking back to the Yuno host. react-router resolves the actual route client-side from `window.location`.
* **BFF calls**: the checkout app's axios `baseURL` is the white-labeled `apiUrl` (`host/<BASE_PATH>/checkout-bff/v1`). After the base-path strip the proxy sees `/checkout-bff/*` and forwards it to `CHECKOUT_BFF_UPSTREAM` (`GET /checkout-bff/v1/checkout-info/{session}`, `POST /checkout-bff/v1/checkout/payment`). The [promotion](https://docs.y.uno/docs/payment-features/promotions) quote doesn't go to the BFF: the SDK inside the checkout asks for it through the backend pass-through (`POST /v1/promotions/quote`), so a proxy that forwards only explicit routes must forward that one too, or the customer silently sees the regular price.
* **Status WebSocket**: `/checkout-websocket-notification-ms/ws/{payment,enrollment}` is forwarded to `BACKEND_WS_URL`.

> [!NOTE]
>
> The BFF host is `<env>.y.uno` directly, with **no** `api-` prefix (`sandbox.y.uno`, `prod.y.uno`), unlike the SDK's REST surface on `api[-env].y.uno`. Set `CHECKOUT_UPSTREAM` and `CHECKOUT_BFF_UPSTREAM` to the same environment as your checkout session.

> [!WARNING]
>
> The `sdk-checkout` app gates the white-labeled `apiUrl` / `assetUrl` against an allowlist (`REACT_APP_WHITE_LABEL_ALLOWED_HOSTS`). To exercise this through the proxy, `localhost` must be on that allowlist in the target environment; otherwise the app ignores the override and calls Yuno directly.

To try it, open `http://localhost:9090<BASE_PATH>/payment?session=<checkout-session>` with a matching `CHECKOUT_UPSTREAM` / `CHECKOUT_BFF_UPSTREAM` for the session's environment. The checkout renders under the non-Yuno origin and calls the BFF back through the proxy.

## `SDK_MAIN_JS` — pinning the SDK version

`SDK_MAIN_JS` decides which build of the SDK every browser loads. It does two related things:

1. **Template injection.** The proxy serves `pages/index.html` with the literal `__SDK_MAIN_JS__` placeholder replaced by this path. A partner page can write `<script src="__SDK_MAIN_JS__">` and get, for example, `/v1.9.4/main.js`.
2. **Version normalization target.** The proxy parses the `/v<x>/` segment out of `SDK_MAIN_JS` and rewrites any incoming `/v<other>/main.js` (and adjacent `/v<other>/*.js`, `/v<other>/*.css`) request to that same version. So if `SDK_MAIN_JS=/v1.9.4/main.js`, a request for `/v1.5.0/main.js` is silently fetched as `/v1.9.4/main.js` from `SDK_UPSTREAM`.

### Resolution order at boot

```text theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
1. process.env.SDK_MAIN_JS                          (if set, used as-is, no upstream call)
2. <SDK_UPSTREAM>/versions.json → latest.version    (auto-detect, 5s timeout)
3. /v1.7/main.js                                    (hard-coded fallback)
```

If steps 1 and 2 both fail, you get the fallback and a warning is logged. Setting `SDK_MAIN_JS` explicitly is the only way to skip the upstream fetch entirely. This is useful when `versions.json` is unreachable, you want a deterministic startup, or the upstream's `latest` is not what you want to test against.

### Format

```bash theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
SDK_MAIN_JS=/v<semver>/main.js
```

`<semver>` matches `[\d.]+(?:-[\w.]+)?`: dot-separated numbers with an optional pre-release suffix.

| Value | When to use it |
| :- | :- |
| `/v1.9/main.js` | Pin to a minor line (whatever the upstream publishes there) |
| `/v1.9.4/main.js` | Pin to an exact patch (most common) |

The path **must** start with `/v` and contain `/main.js` for normalization to work. If the regular expression does not match, the path is used for template injection but version rewriting is disabled.

### Common use cases

**Test a specific SDK release end-to-end:**

```shell theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
SDK_MAIN_JS=/v1.9.4/main.js npm start
```

Every page now loads `v1.9.4`, and any hardcoded `/v<other>/*.js` in partner pages is silently rewritten to `v1.9.4` against `SDK_UPSTREAM`.

**Quiet startup (no upstream `versions.json` call):**

```shell theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
SDK_MAIN_JS=/v1.9.4/main.js npm start
```

Useful in air-gapped environments or when `SDK_UPSTREAM` is a local file server that does not expose `versions.json`.

**Reproduce a customer bug on an older version:**

```shell theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
SDK_MAIN_JS=/v1.7.4/main.js npm start
```

As long as `v1.7.4` is still published on `SDK_UPSTREAM`, every browser that hits the proxy loads it, with no rebuild required.

### Gotchas

* **Card and 3DS upstreams are not affected.** `SDK_MAIN_JS` only pins the main SDK bundle's version. The card micro-app (`/v<x>/pages/*`) and the 3DS micro-app keep their own version segments.
* **Setting it disables auto-detection.** If a newer SDK version is published upstream, you keep loading the pinned version until you change the env var and restart.
* **Restart required.** The value is read once at boot. No hot reload.
* **Mismatch with upstream is silent.** Pinning to a version the upstream does not publish results in a `404` for `/v<your-pin>/main.js`. Check the network tab to spot it.
* **No query strings or hash.** Path only.

## `BASE_PATH` — sub-path mounting

A partner gateway is often **mounted under a sub-path** rather than at the origin root. Zuora, for example, serves the SDK from `https://host/hosted-payment-methods/hosted-payment-form/orchestrator` instead of `https://host/`. Recent SDK builds preserve that prefix on **every** asset, API, and WebSocket request (the configured `apiUrl` / `assetUrl` carry it), so a request for an icon arrives as `…/orchestrator/sdk-web/foo.svg`, not `/sdk-web/foo.svg`.

Without help, those prefixed paths would never match the proxy's root-level routing. `BASE_PATH` closes the gap: set it to the sub-path the proxy is "mounted" under, and the proxy strips the prefix from every incoming request (local routes, the `/v1`–`/v2` backend forward, the asset catch-all, and WebSocket upgrades) **before** routing. The existing root-level rules then match unchanged.

Leave it empty for a root mount (the default: behaviour is identical to not having the feature).

### What it changes

1. **Prefix strip.** A top middleware rewrites `req.url` / `req.originalUrl` to drop `BASE_PATH` so everything downstream operates on root-relative paths. WebSocket upgrades get the same strip on the underlying `http.Server`.
2. **Template injection.** The `__SDK_MAIN_JS__` placeholder is emitted **with** the prefix, so the served landing page points at `<BASE_PATH>/v<x>/main.js`.
3. **`/whitelabel-info`** reports the resolved `basePath` (or `null` at root) alongside the upstream config.

### Format

```bash theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
BASE_PATH=/hosted-payment-methods/hosted-payment-form/orchestrator
```

Leading slash, no trailing slash (trailing slashes are stripped). Empty or unset = root mount.

### Partner page setup

When `BASE_PATH` is set, the partner page must carry the same prefix in two places:

* **Load the bundle** from `http://localhost:9090<BASE_PATH>/v<ver>/main.js`.
* **Initialize** with `apiUrl` / `assetUrl` = `http://localhost:9090<BASE_PATH>`.

```text theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
icon → http://localhost:9090/hosted-payment-methods/.../orchestrator/sdk-web/foo.svg
     → strip BASE_PATH → /sdk-web/foo.svg → SDK_ICONS_UPSTREAM
```

> [!NOTE]
>
> **Versioned `assetUrl`.** You can pin a bundle version on `assetUrl` (`…/orchestrator/v1.0`). The SDK uses that path for JS chunks but **strips the trailing `/v<semver>`** when resolving host-swapped CDN assets (icons and fonts aren't versioned), so both `assetUrl = …/orchestrator` and `assetUrl = …/orchestrator/v1.0` route icons correctly.

### Gotchas

* **The prefix lives in the URL, not a header.** Both the bundle `<script src>` and the `apiUrl` / `assetUrl` must include `BASE_PATH`, or requests land at the root and the strip is never exercised.
* **Strip is exact-prefix.** Only `BASE_PATH`, `BASE_PATH/…`, and `BASE_PATH?…` are rewritten. A path that merely resembles the prefix is left alone.
* **WebSocket upgrades are stripped too**, on the `http.Server` `upgrade` handler, since Express middleware never sees them.

## Building a server like this

### 1. Bootstrap the project

```shell theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
mkdir my-proxy && cd my-proxy
npm init -y
npm install express http-proxy node-fetch@2 dotenv
```

> [!NOTE]
>
> Use `node-fetch@2` (CommonJS) unless you have a build step; v3 is ESM-only.

### 2. Define your upstream map

| Upstream var | Owns these paths |
| :- | :- |
| `CHECKOUT_UPSTREAM` | `/payment`, `/payment/status`, `/enroll` (SPA `index.html`), the CRA bundle `/static/(js\|css\|media)/*`, and root public files (`/favicon.ico`, `/manifest.json`, `/robots.txt`, `/asset-manifest.json`) |
| `CHECKOUT_BFF_UPSTREAM` | `/checkout-bff/*` (checkout BFF; host is `<env>.y.uno`, **no** `api-` prefix) |
| `SDK_UPSTREAM` | `/v<x>/main.js` and everything not matched below |
| `SDK_CARD_UPSTREAM` | `/v<x>/pages/*`, `/v<x>/assets/*` |
| `SDK_3DS_UPSTREAM` | `/challenge.html`, `/redirect.html`, `/session-id.html`, `/assets/(challenge\|redirect\|session-id\|validate-url)*` |
| `SDK_STATIC_UPSTREAM` | `/icons/*`, `/css/*`, `/brands/*`, `/c2p/*`, `/wallets/*`, `/fonts/*` (host-swapped CDN assets) |
| `SDK_ICONS_UPSTREAM` | `/sdk-web/*`, `/flags/*`, bare root brand images (`/Visa.png`, …) |
| `SDK_STATIC_BUNDLES_UPSTREAM` | `/sdk-static-bundles-ms/*` (font stylesheet and font files, Forter script, Riskified SRI beacon) |
| `BACKEND_URL` | `/v1/*`, `/v2/*` (REST API) |
| `BACKEND_WS_URL` | `/checkout-websocket-notification-ms/ws/{payment,enrollment}` (WebSocket only) |
| `BASE_PATH` | *(optional)* sub-path the proxy is mounted under, stripped before routing; empty = root |

`SDK_CARD_UPSTREAM` and `SDK_3DS_UPSTREAM` default to `SDK_UPSTREAM` when unset, and `BACKEND_WS_URL` defaults to `BACKEND_URL`. Keep this fallback behaviour, it makes single-env testing easier. `SDK_STATIC_UPSTREAM` / `SDK_ICONS_UPSTREAM` / `SDK_STATIC_BUNDLES_UPSTREAM` are the exception: they default to the fixed `sdk.prod.y.uno` / `icons.prod.y.uno` / `prod.y.uno` hosts, **not** to `SDK_UPSTREAM`. The first two are the same in every environment; set `SDK_STATIC_BUNDLES_UPSTREAM` to `staging.y.uno` to test the Riskified SRI beacon outside production. `CHECKOUT_UPSTREAM` / `CHECKOUT_BFF_UPSTREAM` default to sandbox (`checkout.sandbox.y.uno` / `sandbox.y.uno`); the checkout-asset rule is checked **before** the SDK icon rules so the CRA bundle and root files (`/favicon.ico`, …) don't fall through to `icons.prod.y.uno`.

> [!NOTE]
>
> If you need to emulate a partner gateway mounted under a sub-path, register a strip middleware **before** all routes that rewrites `req.url` / `req.originalUrl` to drop `BASE_PATH` (and apply the same strip on the `http.Server` `upgrade` handler). Every route below then sees root-relative paths. Skip it entirely when `BASE_PATH` is empty. See [`BASE_PATH`: sub-path mounting](#base_path--sub-path-mounting).

### 3. Set up CORS as the proxy's responsibility

```javascript theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
app.use((req, res, next) => {
  const origin = req.headers.origin
  if (origin) {
    res.set('access-control-allow-origin', origin)
    res.set('access-control-allow-credentials', 'true')
    res.set('vary', 'origin')
  } else {
    res.set('access-control-allow-origin', '*')
  }
  res.set('access-control-allow-methods', req.headers['access-control-request-method'] || 'GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS')
  res.set('access-control-allow-headers', req.headers['access-control-request-headers'] || '*')
  res.set('access-control-expose-headers', '*')
  res.set('access-control-max-age', '86400')
  if (req.method === 'OPTIONS') return res.status(204).end()
  next()
})
```

Echo the caller's origin (not `*`) so credentialed requests work, and short-circuit preflights. When you later forward upstream responses, strip every `access-control-*` header from the upstream or it will override yours.

### 4. Filter hop-by-hop headers in both directions

Per [RFC 7230 §6.1](https://datatracker.ietf.org/doc/html/rfc7230#section-6.1):

```javascript theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
const HOP_BY_HOP = new Set([
  'host', 'connection', 'keep-alive',
  'proxy-authenticate', 'proxy-authorization',
  'te', 'trailer', 'transfer-encoding', 'upgrade',
  'content-length', // node-fetch sets this itself
])
```

Filter these out of both inbound (request to upstream) and outbound (upstream to client) headers. Forgetting `content-length` is the classic bug: node-fetch sets it, but if you also copy the original value the response truncates.

### 5. Forward the API surface

```javascript theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
app.all('/v1/*', forwardToBackend)
app.all('/v2/*', forwardToBackend)

async function forwardToBackend(req, res) {
  const targetUrl = `${BACKEND_URL}${req.originalUrl}`
  const headers = pickRequestHeaders(req) // filters HOP_BY_HOP
  delete headers.cookie                   // partner cookies don't belong on api.y.uno
  const init = { method: req.method, headers }
  if (req.method !== 'GET' && req.method !== 'HEAD') {
    // express.json() consumed the original body; re-serialize it.
    init.body = req.body && Object.keys(req.body).length ? JSON.stringify(req.body) : undefined
    if (init.body && !headers['content-type']) headers['content-type'] = 'application/json'
  }
  const upstream = await fetch(targetUrl, init)
  res.status(upstream.status)
  for (const [k, v] of upstream.headers.entries()) {
    const lk = k.toLowerCase()
    if (HOP_BY_HOP.has(lk)) continue
    if (lk.startsWith('access-control-')) continue   // proxy owns CORS
    res.set(k, v)
  }
  res.send(await upstream.text())
}
```

`express.json()` has already consumed the request body, so for non-GET methods you re-serialize `req.body`. Don't try to `req.pipe(upstream)` after the body is consumed.

> [!NOTE]
>
> Drop the `Cookie` header before forwarding. The partner page's browser cookies belong to the proxy origin (session, analytics, URL-valued ones like `spage`) and a genuine cross-origin call to `api.y.uno` would never carry them. Forwarding them only risks the upstream WAF rejecting the request with a `403`. The API authenticates via the public API key, not cookies. (WebSocket upgrades are the exception; see step 7.)

### 6. Catch-all proxy for SDK assets

```javascript theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
app.use((req, res, next) => {
  if (req.method !== 'GET' && req.method !== 'HEAD') return next()
  proxyToUpstream(req, res, next)
})

async function proxyToUpstream(req, res, next) {
  const upstreamBase = pickSdkUpstream(req.path)   // checkout / 3DS / card / static-bundles / static / icons / SDK
  const targetUrl = `${upstreamBase}${normalizePath(req.originalUrl)}`
  const upstream = await fetch(targetUrl, { redirect: 'follow', headers: { /* accept, user-agent */ } })
  if (upstream.status === 404) return next()
  res.status(upstream.status)
  for (const h of ['content-type', 'cache-control', 'etag', 'last-modified']) {
    const v = upstream.headers.get(h)
    if (v) res.set(h, v)
  }
  upstream.body.pipe(res)   // stream — don't buffer, assets can be big
}
```

> [!WARNING]
>
> Register the catch-all last. It matches everything, so any middleware added after it is unreachable unless you guard it explicitly.

### 7. Handle WebSocket upgrades on the http.Server

Express middleware does not see `Upgrade` requests. Hook into the http server directly:

```javascript theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
const wsProxy = httpProxy.createProxyServer({ changeOrigin: true, ws: true })
const server = app.listen(PORT)
server.on('upgrade', (req, socket, head) => {
  const target = pickWsTarget(req.url)   // BACKEND_WS_URL or SDK_UPSTREAM
  wsProxy.ws(req, socket, head, { target })
})
```

`http-proxy` negotiates `ws://` vs `wss://` from the target URL scheme.

### 8. Wire up environment variables

Use `dotenv`. Document **per-environment** values, not just defaults. For Yuno:

* SDK services follow `<service>[.<env>].y.uno`: `sdk-web.y.uno`, `sdk-web.staging.y.uno`, `sdk-web.dev.y.uno`.
* API surface uses `api[-<env>].y.uno`: `api.y.uno`, `api-staging.y.uno`, `api-dev.y.uno`. **Note the hyphen, not a dot.**
* The WebSocket service has **no** `api-` prefix; it's `<env>.y.uno` directly (`y.uno`, `staging.y.uno`, `dev.y.uno`).

These naming inconsistencies cause more 404s than any other class of bug. Encode them in your `.env.example` so users don't guess.

### 9. Ship a minimal landing page

Serve `index.html` at `/` and a `/whitelabel-info` JSON endpoint that returns the resolved upstream config. The landing page calls the JSON endpoint and renders it, so anyone debugging the proxy sees exactly what's routed where without grepping logs.

## Pitfalls and edge cases

* **Route order matters.** The SDK catch-all is registered last. Anything you `app.use` after it never runs.
* **CORS authority must be the proxy.** Letting upstream `access-control-*` headers through means credentialed cross-origin requests randomly fail when the upstream's allow-list does not include `localhost`.
* **Hop-by-hop headers are bidirectional.** Strip them on both legs. `content-length` is the one that bites.
* **Body consumption is a one-shot.** Once `express.json()` parses a request, the underlying stream is drained. Re-serialize from `req.body` if you need to forward a `POST`.
* **Streaming, not buffering, for assets.** `upstream.body.pipe(res)` keeps memory flat even for multi-MB bundles.
* **Version normalization is `SDK_UPSTREAM`-only.** Card and 3DS micro-apps have their own version segments; rewriting them breaks the upstream URL. The static / icons CDNs aren't versioned, so they aren't normalized either.
* **Static CDN assets are host-swapped too.** Recent SDK builds rewrite their hard-coded `icons.prod.y.uno` / `sdk.prod.y.uno` asset URLs onto the white-label host, so the proxy must forward `/icons`, `/css`, `/brands`, `/c2p`, `/wallets`, `/fonts` → `sdk.prod.y.uno` and `/sdk-web`, `/flags`, bare `/*.png` → `icons.prod.y.uno`. Older SDK builds load these straight from the CDN and never reach the proxy. Exercising this end-to-end needs a recent SDK build **and** a partner page that inits with `{ apiUrl: '<proxy origin>' }` (or `assetUrl`).
* **Fonts need their own route from SDK 1.10.9.** The SDK loads its font stylesheet from `prod.y.uno/sdk-static-bundles-ms/…`, host-swapped onto the white-label host. Without a `/sdk-static-bundles-ms/*` → `prod.y.uno` rule, the request falls through to `SDK_UPSTREAM` and returns `404`. The SDK then renders in the system font, with no error.
* **Don't forward the partner page's cookies to the API.** Strip `Cookie` on `/v1`/`/v2` forwards. The browser's localhost cookies (session, analytics, URL-valued ones like `spage`) don't belong on a cross-origin call to `api.y.uno` and can trip the upstream WAF with a `403`. The API authenticates via the public API key.
* **WebSocket auth is whatever headers `http-proxy` sees.** Do **not** strip `cookie` or `authorization` from WS upgrades; the cookie strip applies only to the HTTP `/v1`/`/v2` backend forwards.
* `.env` is gitignored. Always keep `.env.example` in sync; it is the spec for anyone cloning the repo.

## Routes a partner proxy must forward

A production partner gateway needs the same split as this harness (this table is the reference; the lists above describe the harness). Every path arrives under the partner's base path, prefixed exactly as `apiUrl` / `assetUrl` carry it. Check this list before upgrading the SDK line.

**Match the rules in this order; the first match wins.** Several shapes overlap (`/v1/*`, `/v<major.minor>/*`, `/v<card-semver>/pages/*`), so an unordered set of prefix or regex rules sends card pages or API calls to the wrong host.

| # | Path | Forward to | Needed from |
| :- | :- | :- | :- |
| 1 | `/v1/*`, `/v2/*` (HTTP and WebSocket) | `api[-<env>].y.uno` | Always |
| 2 | `/checkout-websocket-notification-ms/ws/*` (WebSocket) | `<env>.y.uno` (`prod.y.uno` in production) | Always |
| 3 | `/payment`, `/payment/status`, `/enroll`, `/static/(js\|css\|media)/*`, `/favicon.ico`, `/manifest.json`, `/robots.txt`, `/asset-manifest.json`, `/checkout-bff/*` | `checkout[.<env>].y.uno` / `<env>.y.uno` | Payment Link white-label |
| 4 | `/challenge.html`, `/redirect.html`, `/session-id.html`, `/assets/(challenge\|redirect\|session-id\|validate-url)*` | `sdk-3ds[.<env>].y.uno` | 3DS |
| 5 | `/v<card-semver>/pages/*`, `/v<card-semver>/assets/*` | `sdk-web-card[.<env>].y.uno` | Always |
| 6 | `/sdk-static-bundles-ms/*` (keep the query string) | `prod.y.uno` (`staging.y.uno` for sandbox and staging Riskified SRI) | **SDK 1.10.9+** (font stylesheet); **SDK 1.11.16+** (Forter script, Riskified SRI beacon) |
| 7 | `/icons/*`, `/css/*`, `/brands/*`, `/c2p/*` | `sdk.prod.y.uno` | SDK 1.9.32+ |
| 8 | `/wallets/*` (Samsung Pay Portuguese button), `/fonts/*` (Checkout Builder custom fonts) | `sdk.prod.y.uno` | **SDK 1.11.16+** |

The **Needed from** column is the SDK release from which the SDK sends that request to the white-label host. The assets themselves are older (the Forter script has lived under `/sdk-static-bundles-ms/` since SDK 1.5.19, the Riskified SRI beacon since 1.6.4, the Samsung Pay Portuguese button under `/wallets/` since 1.10.9), but before the release listed the SDK requested them directly from `*.y.uno`, so a partner proxy never saw them and needed no rule. Adding the rules before upgrading is harmless.
\| 9 | `/sdk-web/*`, `/flags/*`, bare brand images (`/Visa.png`, …) | `icons.prod.y.uno` | SDK 1.9.32+ |
\| 10 | `/v<major.minor>/*` (SDK bundle and chunks) and anything else | `sdk-web[.<env>].y.uno` | Always |

* **CORS.** Fonts (`/sdk-static-bundles-ms/*`, `/fonts/*`) and the SRI fraud scripts are fetched in CORS mode from the merchant page, so the gateway must return `Access-Control-Allow-Origin` for the merchant origin. `sdk.prod.y.uno/fonts/*` sends none, so forwarding the response untouched is not enough.
* **Reject `.` and `..` path segments** before forwarding. Otherwise `/sdk-static-bundles-ms/../…` resolves to any path on the upstream host, including the production API gateway.
* **Regions.** With an `apiUrl` override the SDK no longer adds the public API key's region to hosts, so a gateway serving MENA keys must route them to the regional hosts itself.
* **Versioned `assetUrl`** (for example `…/orchestrator/v1.0`). Chunks are requested under that version segment, so the gateway must map it to a published `sdk-web` path (the harness normalizes it to the latest published version).
* **Payment Link.** Rewrite the absolute `checkout.<env>.y.uno` origin in the served `index.html` to your base path, as the harness does, or the bundle loads from the Yuno host.
* **Fallback.** SDK 1.11.16+ loads the fraud scripts, the Samsung Pay Portuguese button and Checkout Builder fonts from Yuno again when the gateway can't serve them, so a missing rule degrades instead of breaking. Keeping every request off `*.y.uno` still needs every rule above.

## Verification checklist

Once your proxy is running, verify in browser DevTools:

1. **Network tab**: no requests to any `*.y.uno` host originate from the merchant page. All traffic is to the proxy origin.
2. `window.SdkPayments` is defined; `window.Yuno` is either undefined or a legacy alias.
3. `sdk-payments-ready` event fires on `document` after the SDK boots.
4. No `yuno-*` DOM tokens in the rendered output, except for the trust-mark allow-list (`yuno-badge`, `secure-by-yuno`, `yuno-typography-provider`, `yuno-c2p`, `yuno-redirect`, `yuno-debug`, `data-yuno-session-id`).

## Reference implementation

The full source lives in the [`yuno-sdk-web/white-label-proxy-server`](https://github.com/yuno-payments/yuno-sdk-web/tree/main/white-label-proxy-server) repository. About 350 lines in `server.js`; the whole thing fits in one file because there is no business logic, just routing and header hygiene.

## See also

* [White Label (Web SDK)](https://docs.y.uno/docs/sdks/customization/web/white-label.md): the SDK-side overrides this harness verifies.
* [yuno-payments/yuno-sdk-web/tree/main/white-label-proxy-server](https://github.com/yuno-payments/yuno-sdk-web/tree/main/white-label-proxy-server): full source.
* [RFC 7230 §6.1: Connection-specific headers](https://datatracker.ietf.org/doc/html/rfc7230#section-6.1)
* [http-proxy WebSocket docs](https://github.com/http-party/node-http-proxy#proxying-websockets)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.