Run the site proxy
The site proxy is code your organization deploys in front of one of its sites. It receives every request for the site’s host and:
- forwards every
/edgekit/request to your tenant host, including the script it adds to your pages,/edgekit/ek.js; - fetches everything else from your site’s own server, which these pages call the upstream;
- on HTML pages, asks decide for your
paywallfeature on the server and, when the outcome does not allow the page, removes the gated part it finds before the page reaches the browser.
Your organization runs its own copy, one per site. EdgeKit does not deploy it, update it or roll it back. The
script at /edgekit/ek.js is EdgeKit’s, served by your tenant host, so it updates without a redeploy of your copy. The code it
runs is createProxy in @edgekitcloud/proxy.
What it needs
Section titled “What it needs”- A route for the whole host: every request for the site’s host must reach your copy. A narrower route of your own on the same host takes precedence for its paths, which then skip the proxy, and the proxy cannot detect this.
- Your site’s origin in Allowed origins: the proxy’s decide call carries the page’s origin, and browser requests
through
/edgekit/carry theirs. Set it on Delivery › Delivery › Sites, then deploy. See Allow your site’s origins. - A deployed feature named
paywallon the site. It is the only feature the proxy asks for. If the deployment does not carry it, decide lists it as unknown and the proxy treats every page it decides as gated. - The settings below, as environment variables of your copy.
Settings
Section titled “Settings”Every setting starts with EDGEKIT_. If a required setting is missing or invalid, the proxy passes every request to
your site unchanged. An invalid optional setting takes its default. Either way the proxy logs one warning per problem
when it starts, to your copy’s own log.
| Setting | Required | Default | What it does |
|---|---|---|---|
EDGEKIT_TENANT_HOST |
Yes | Your tenant host, with or without https://. No path |
|
EDGEKIT_SITE_ID |
Yes | The site this copy fronts | |
EDGEKIT_UPSTREAM_URL |
Yes | Your site’s own server. Only its origin is used; a path is ignored with a warning | |
EDGEKIT_BODY_SELECTOR |
No | none | CSS selector for the gated region |
EDGEKIT_PREVIEW_CHILDREN |
No | 2 |
How many child elements of the gated region a truncated page keeps |
EDGEKIT_IGNORE_PATHS |
No | none | Regular expression tested against the path. A matching page is never decided |
EDGEKIT_ACCESS_DEFAULT |
No | metered |
The access fact for a page that does not mark itself free |
EDGEKIT_SECTION_DEFAULT |
No | empty | The section fact for a page that declares none |
EDGEKIT_FACT_OVERRIDES |
No | {} |
JSON object from fact name to source, below |
EDGEKIT_BYPASS_BOT_CATEGORIES |
No | ["Search Engine Crawler"] |
JSON array of verified-bot categories that get the whole page |
EDGEKIT_BYPASS_IPS |
No | [] |
JSON array of connecting IPs that get the whole page, such as a licensed fetcher |
EDGEKIT_SIGN_IN_URL |
No | none | Absolute URL the panel links to for sign-in |
EDGEKIT_SUBSCRIBE_URL |
No | none | Absolute URL the panel links to for subscribing |
EDGEKIT_CLIENT_IP_KEY |
No | none | Secret. Signs each user’s IP address for EdgeKit’s rate limits, below |
A JSON setting may be a JSON string or a native object or array.
Which requests it changes
Section titled “Which requests it changes”Only a GET answered 200 with content-type: text/html goes through the steps below. Every other response,
including redirects, errors, assets and form posts, passes through byte for byte.
The proxy reads every fact from <head>, so it reads the page to the end of <head> and then sends the response,
rewriting the rest of the page as your server sends it. One case reads further first: when the outcome does not
allow the page and neither edgekit:gated nor EDGEKIT_BODY_SELECTOR names the gated region, the proxy reads on
until the region appears. A page without that region, or whose server left it out, is then read to its end, so set
one of the two to avoid the wait. If <head> runs past 2 MB, the proxy sends the page unchanged; a gated region
past the first 2 MB is not found.
A GET whose Accept header asks for text/markdown reaches your site’s server asking for text/html first,
then any type. Your server must answer with HTML for the proxy to run these steps; a markdown answer passes through
whole. If your edge converts pages to markdown, it converts the page the proxy sends.
1. It reads facts off the page’s <head>
Section titled “1. It reads facts off the page’s <head>”Your page can state its own facts with meta tags in <head>, and each one comes first for its fact:
<meta name="edgekit:article_id" content="cms-12345" /><meta name="edgekit:access" content="premium" /><meta name="edgekit:section" content="Politics" /><meta name="edgekit:section" content="Europe" /><meta name="edgekit:published_at" content="2026-05-06T08:00:00Z" /><meta name="edgekit:gated" content=".article-body" />edgekit:access gives decide the product each page belongs to; without it, access is free or
EDGEKIT_ACCESS_DEFAULT. edgekit:gated names the gated region (step 3). Structured data is read from <head>
only: a JSON-LD block in <body> is ignored.
| Fact | Where it comes from |
|---|---|
article_id |
edgekit:article_id as written, else the canonical link, else the article’s mainEntityOfPage or url in the page’s structured data, else the request path. The path only, never the host |
sections |
Every edgekit:section, else every articleSection in the structured data, else the article:section meta tag |
section |
The first of sections, else EDGEKIT_SECTION_DEFAULT |
access |
edgekit:access as written, else free when the structured data says isAccessibleForFree is true, else EDGEKIT_ACCESS_DEFAULT |
published_at |
edgekit:published_at, else datePublished, else the article:published_time meta tag, as ISO 8601 UTC. Left out when the value found does not parse |
page_url |
The request URL without its query string |
EDGEKIT_FACT_OVERRIDES replaces any of these six, including a value the page states. Each value is ld:<path> to
read a field of the article’s structured data, <selector>@<attribute> to read the first matching element’s
attribute in <head>, or a literal value.
The proxy holds no content-signing secret, so these facts reach decide unsigned, at the unverified trust level. A
canvas that branches on trust level sees unverified.
2. It asks decide
Section titled “2. It asks decide”The proxy posts to /edgekit/v1/decide on your tenant host for the paywall feature, with the facts, the page’s
origin, the user’s Cookie, User-Agent, Accept-Language and Referer headers, and the country and IP headers
your edge sets. A gift link in the page URL’s
_gt parameter is sent too, and so is a newsletter link in its ek_nl
parameter. So is an outcome preview’s token, from the page URL’s edgekitPreview parameter, else
the edgekit_preview cookie, as the x-edgekit-preview header; ?edgekitPreview=off sends none. See
Preview an outcome on your site. The call has a 2-second deadline.
It skips decide when the request’s verified-bot category is in EDGEKIT_BYPASS_BOT_CATEGORIES, when its connecting
IP is in EDGEKIT_BYPASS_IPS, or when the path matches EDGEKIT_IGNORE_PATHS.
Experiment exposures
Section titled “Experiment exposures”When decide’s answer exposed the request to one of EdgeKit’s own experiments, the proxy records it, with no change
to your site. It posts one experiment_exposure event per entry of the answer’s exposures to
/edgekit/a/t on your tenant host, in one request. Each event has a new event id and the entry’s unitId as
unit_id. The request carries no cookie and no header from the user’s request.
- The page does not wait for it. The proxy hands the request to your platform to finish after the page is sent,
through the adapter’s
waitUntil. On a platform with no such hook, such as a Cloudflare Snippet, it can be cut off when the page is returned. - Every decided page sends them again. Each event is a billed event: one per decided page for each experiment the answer exposed.
- An answer with
preview: truesends none, so a page under an outcome preview records no exposure. - When your tenant host is on the proxy’s own Cloudflare zone, bind the collector Worker as
EDGEKIT_COLLECTOR, besideEDGEKIT_DECIDE. Without it the request does not reach the collector and no exposure is recorded. - If the collector does not accept the events within 2 seconds, the proxy logs an
exposures_failedwarning. The page is not affected, and nothing is sent again.
See Exposures.
3. It picks a mode
Section titled “3. It picks a mode”| Mode | When | The page |
|---|---|---|
bot |
A verified bot in a bypassed category | Whole, decide not called, your caching headers kept |
allow |
Decide allowed the page, or the path is ignored | Whole |
truncated |
A gated region was found and the outcome does not allow | The first EDGEKIT_PREVIEW_CHILDREN child elements of the region are kept and the rest removed |
overlay |
No gated region was found and the outcome does not allow | Whole. The panel covers it in the browser, and the gated text stays in the page source |
unavailable |
Decide timed out, could not be reached, answered an error status (such as 403 for an origin not in Allowed origins) or answered something other than a decision |
Whole, with no panel |
The gated region is the first of these that applies:
- The page’s
edgekit:gatedmeta tag. EDGEKIT_BODY_SELECTOR.- A
cssSelectorthe page’s structured data declares for a part that is not free, if it is a plain.classor#idthat occurs in the page. - Elements with the class
edgekit-gated.
With none of them, the mode is overlay. A selector the proxy cannot parse is skipped with a warning: a bad
edgekit:gated falls through to EDGEKIT_BODY_SELECTOR, and when neither parses the mode is overlay. edgekit:gated and EDGEKIT_BODY_SELECTOR are used as typed: if one matches nothing on the page, nothing
is removed and the panel covers the page as in overlay. In truncated mode, text that sits directly in the region, outside any child element, is not removed.
4. It rewrites the page
Section titled “4. It rewrites the page”In one pass over the page, the proxy:
- adds to
<head>a<script type="application/json" id="edgekit-decision">with the decision, the facts and the mode, and<script type="module" src="/edgekit/ek.js">; - in
truncatedmode, removes the region’s extra children and leaves an empty<div data-edgekit-panel>where the panel goes; - adds decide’s
Set-Cookieheaders, and theedgekit_previewcookie when the page URL carriesedgekitPreview(deleted foroff); - when decide answered or a cookie is set, sets
Cache-Control: private, no-storeand removesETag,Last-ModifiedandExpires, so no shared cache stores one user’s page for another.
The edgekit_preview cookie does not depend on decide. When the page URL carries edgekitPreview, every HTML page
the proxy sends sets the cookie, or deletes it for off, with Cache-Control: private, no-store. This includes pages
it does not decide or rewrite: a bypassed bot, an ignored path, a page whose <head> runs past 2 MB, and your
upstream’s page after a failed rewrite.
It keeps your security headers, such as Content-Security-Policy, Strict-Transport-Security and
X-Frame-Options. Its script is served from your own origin, so script-src 'self' allows it. The panel is styled by
a constructed stylesheet, which style-src does not govern, so your policy needs no 'unsafe-inline' for it.
The script draws a panel in truncated and overlay modes and never decides again. The panel’s copy is built-in
English text chosen by the outcome’s id. Its link is the url in the outcome’s value when there is one, else
EDGEKIT_SUBSCRIBE_URL or EDGEKIT_SIGN_IN_URL.
When the outcome has an experience on the site, the script shows it. An inline experience takes the panel’s place, and the panel is drawn instead if the experience fails. Any other display is drawn beside the panel.
When something fails
Section titled “When something fails”| What failed | What the browser gets |
|---|---|
Your tenant host, on an /edgekit/ request |
502 with the text EdgeKit is unreachable |
| Your upstream | 502 with the text Bad gateway |
| Decide, or its 2-second deadline | The whole page, in unavailable mode |
| The rewrite, after decide answered | Your upstream’s page, without decide’s cookies or headers |
| The request that records exposures | The same page. The exposures are not recorded |
Any status your tenant host answers on an /edgekit/ request, such as a 429, passes through unchanged.
Rate limits behind the proxy
Section titled “Rate limits behind the proxy”Decide’s browser path allows 200 requests per 10 seconds per client per site. EdgeKit sees requests from your copy,
not from your users, so without EDGEKIT_CLIENT_IP_KEY all users of the site can share one client’s budget.
With the key, the proxy signs each user’s IP address on every request it sends to your tenant host, and EdgeKit counts each user on their own. EdgeKit issues the key for one site; ask for it. A signature that does not verify, or is more than 60 seconds old, is ignored, never refused: the request is then counted against the address that connected.