Call the tenant host directly
If you cannot route /edgekit/ on your own domain, your pages can send EdgeKit requests to the tenant host itself,
such as https://your-tenant-host/edgekit/v1/decide. The browser client does this when you set its baseUrl
(BrowserClientOptions).
Keep the /edgekit/v1/ path on the tenant host too. The browser credential (the site header and the origin check) is
on /edgekit/v1/ paths on either host. On the tenant host, /v1/decide takes an API key and refuses a browser with
401.
What you lose
Section titled “What you lose”- One session for both hosts, unless your organization’s cookie domain covers both. By default the sign-in cookie
is host-only: it stays on the host the user signed in through. When your pages sign in through the tenant host, and
the tenant host shares your site’s domain, such as
edgekit.example.comforwww.example.com, later requests to the tenant host keep the session. A session started on your own host, through the/edgekit/path, is not sent to the tenant host. With a cookie domain such asexample.com, one session serves both hosts. A tenant host on another domain never gets the cookie. Without a session, decide still answers200, as for an anonymous device, with no error, and requests that need a signed-in user answer401unauthorized. - Same-origin requests: every request is cross-origin, so the browser sends a CORS preflight first. Add the tenant
host to your Content Security Policy’s
connect-src. - First-party analytics: to send events to the tenant host, set the tracker’s
collectorOriginto the tenant host and itspathPrefixto an empty string (EdgeKitTrackerOptions). The collector answers there at/a/t, without the/edgekitprefix. Events then go to a host other than your page’s own.
How cross-origin requests are checked
Section titled “How cross-origin requests are checked”- The preflight: the tenant host answers a preflight from any origin, for the methods the route serves. It
allows the request headers
content-typeandx-edgekit-site-id, and decide also allowsx-edgekit-preview. A browser may reuse the answer for 10 minutes. The preflight grants nothing: it cannot see which site is asked for. - The request: the real request names its site in
x-edgekit-site-id, and itsOriginis checked against that site’s allowed origins. An allowed origin getsAccess-Control-Allow-Originwith its own value, andAccess-Control-Allow-Credentials: true. - A refusal answers
403forbiddenwith no CORS headers, so the browser reports a CORS error and your code cannot read the body.
The browser cannot send an Authorization header to the tenant host: the preflight does not allow it. API keys
belong on servers.
/edgekit/v1/id/config and /edgekit/v1/id/traits skip the origin check: they carry no credential and answer
Access-Control-Allow-Origin: *.