SHADE is young: 0.1.0-next.2 is a pre-release, and 0.1.0 isn't out yet.

SHADE
Run SHADE

Hosting the site on a static host

The site is static files, so a static host can serve it instead of the site's Caddy image. The site's build writes what the host needs around those files: the same security and cache headers, the redirects and the not-found pages per language. SHADE itself still runs on your own server (Setting up an instance or Self-hosting without Coolify).

Where to host it

The default keeps visitors' data in the EU: the site's Caddy image on a server in the EU, or on the client's own. A static host sees every visitor's requests, and on some setups their personal data (Privacy). Choosing a host outside the EU is the business's decision: name the transfer in the site's privacy statement.

  1. In the EU: the site's Caddy image on your own server, beside SHADE or on its own, at a European provider (Setting up an instance, Site (static) and preview). Everything stays on servers you choose. SHADE does not yet write files for a European static host.
  2. Cloudflare (Workers with static assets), below. Cloudflare is a US company.
  3. Netlify, below. Netlify is a US company.

SHADE's own site runs on Cloudflare.

What still needs a server

The static host serves pages, assets, media and the search index. Three things are not files:

  • The preview (/preview, drafts for the team). It runs on the site's Node server (Dockerfile target preview) at its own address, as the website module's Preview address. No static host serves it.
  • Personal parts of pages (server islands: the Account greeting, a user's own data). The site's Node server on your instance renders them for each visitor. On Cloudflare the browser asks it directly, at an address of its own under SHADE's; on Netlify they go through the host.
  • Forms, sign-in and accounts call SHADE's account API (/api/v1/account/*), which runs on SHADE's public role.
Caddy image (static, runner)CloudflareNetlify
Pages, assets, media, searchyesyesyes
Security and cache headersCaddyfile_headers (the Worker's own answers set them itself)_headers
Redirects (301/302)redirects.caddy_redirects (at most 1,000 redirects)_redirects
Not-found page per languageyesyes (nearest 404.html)yes (a rule per language)
Personal parts (islands)the Node serverthe Node server, asked directly at its own addressthe Node server, through an Edge Function
/api/v1/account/*on the site's domainSHADE's own address; on the site's domain only if you switch the forwarding onon the site's domain, through an Edge Function
Per-visitor limits on the account APIyesdirect: yes; forwarded: with SHADE_PROXY_SECRETwith SHADE_PROXY_SECRET
/previewthe runner onlyno: the Node server's own addressno: the Node server's own address

Cloudflare

The site runs on Cloudflare Workers with static assets: the build's files are the assets, served as they are. Cloudflare only ever serves public files. Everything personal stays between the visitor's browser and your instance:

  • Forms, sign-in and accounts go from the browser to SHADE's public role at its own address (api.example.com).
  • Personal parts of pages come from the site's Node server on your instance, at an address under SHADE's (islands.api.example.com). The build seals each part's content with SHADE_ISLAND_SECRET, so the page holds nothing anyone can read or change. In the browser, the page asks the Node server for each part. The Node server opens it, asks the account API who the visitor is with their own cookie, and answers private, no-store, to the site's own address only. Without a session it renders the part for nobody (the Sign in link, say).
  • The sign-in cookie is set for api.example.com and its subdomains, never for the site's domain, so the browser never sends it to Cloudflare.

A small Worker, @shadestack/cloudflare, can forward /api/v1/account/* on the site's own domain. That is off by default, because personal data would then pass through Cloudflare (below).

Setting up the instance

On your instance, next to SHADE's public role at api.example.com:

  1. The site's Node server (the preview container, Setting up an instance, Site (static) and preview) gets a second domain under SHADE's: https://islands.api.example.com. Give it the same SHADE_ISLAND_SECRET as the build (at least 32 characters, openssl rand -base64 48). It answers the island route, /shade-island, there.
  2. SHADE's containers (every role) get SHADE_ACCOUNT_URL=https://api.example.com and SHADE_ACCOUNT_COOKIE_DOMAIN=api.example.com. The second sets the sign-in cookie for api.example.com and its subdomains, so the Node server at islands.api.example.com gets it with each island request. SHADE refuses to start with a domain that SHADE_ACCOUNT_URL is not part of. It warns when the domain takes in the site's own address (example.com for a site at www.example.com): Cloudflare would then get every signed-in visitor's cookie.
  3. The Site URL (Settings) is the site's address, https://www.example.com. The account API and the island route answer the browser only from there.

The site and SHADE must share a domain (www.example.com and api.example.com). Browsers treat a different domain as another site and block its cookies.

Building

Set SHADE_STATIC_HOST=cloudflare, the island secret and the island route's address when building (or shade({ staticHost: 'cloudflare' }) in astro.config.mjs):

SHADE_API_URL=https://api.example.com SHADE_API_TOKEN=… \
SHADE_ACCOUNT_URL=https://api.example.com \
SHADE_STATIC_HOST=cloudflare \
SHADE_ISLAND_SECRET=… SHADE_ISLAND_URL=https://islands.api.example.com \
pnpm --filter @shadestack/site build
  • SHADE_ISLAND_SECRET: the Node server's. SHADE_ISLAND_URL: where the pages ask for their personal parts. Each page names it in <meta name="shade-island-url">, and its Content-Security-Policy allows it. Without the two the build warns, and personal parts keep their placeholder.
  • SHADE_ACCOUNT_URL: where visitors' browsers reach the account API, SHADE's own address.

The folder to upload is site/dist/client, with _headers, _redirects and a copy of each language's not-found page as <language>/404.html. The build leaves out redirects.caddy, which only Caddy reads.

The Worker's settings

The site has wrangler.jsonc and worker.ts in its root. For a site of your own, copy the template from @shadestack/cloudflare (template/) and change name:

  • assets.directory is the build (dist/client), not_found_handling: "404-page" serves the nearest 404.html, html_handling: "drop-trailing-slash" serves each page at its own address (/over-ons, as the site's Caddy does), and run_worker_first sends only /api/v1/account/* to the Worker.
  • With the forwarding off (the default) the Worker answers /api/v1/account/* with 404 and needs no settings.

Deploy with pnpm exec wrangler deploy in the site's folder, after the build. pnpm preview:cloudflare runs the same Worker on your own machine (wrangler dev, Cloudflare's runtime, no account needed).

Forwarding the account API on the site's domain (off by default)

To keep forms, sign-in and accounts on the site's own domain, set ACCOUNT_API_URL in the Worker's vars to SHADE's public role. Build the site with SHADE_ACCOUNT_URL set to the site's own address. The Worker then forwards /api/v1/account/* there:

  • with its own Host, the visitor's address in X-Forwarded-For, and the site's host and scheme in X-Forwarded-Host and X-Forwarded-Proto; it drops forwarding headers a visitor sent;
  • passing cookies, the body (streamed) and every Set-Cookie of the answer through, without following redirects;
  • allowing GET, HEAD, POST, PUT, PATCH and DELETE (405 otherwise), bodies up to 10 MB (413 past that; the API's own limit still applies), and answering 502 when SHADE cannot be reached;
  • keeping the API's own Cache-Control (no-store when it sends none), and adding the site's security headers.

Switching it on is your choice. Every form, sign-in and account request then passes through Cloudflare, a US company: a transfer of personal data outside the EU. Name Cloudflare as a processor in the site's privacy statement. Have Cloudflare's data processing agreement in place, and the basis for the transfer it relies on (the EU–US Data Privacy Framework or standard contractual clauses). The sign-in cookie is then the site's, so Cloudflare gets it with every request a signed-in visitor makes. The default above avoids all of this.

The visitor's address

When forwarding, the Worker calls the API from Cloudflare's own addresses. Without more, SHADE counts every visitor as one address, and the account API's per-address limits (sign-in, forms) apply to all of them together. A shared secret fixes that:

  1. Make a secret of at least 32 characters: openssl rand -base64 48.
  2. On SHADE, set it as SHADE_PROXY_SECRET on the API's public role (in Coolify, the public container's environment) and deploy again.
  3. Give the Worker the same value: wrangler secret put SHADE_PROXY_SECRET. The Worker reads it when a request comes in; it is never written into a file or the build.

With both set, a request from the Worker carries the secret in X-Shade-Proxy-Secret and the visitor's address (Cloudflare's CF-Connecting-IP) in X-Shade-Client-Ip. SHADE compares the secret in constant time and only then counts the request by that address. A wrong or missing secret does not break the site: the request still works, counted by Cloudflare's address, and SHADE's log says so once (a warn line: a request carried X-Shade-Proxy-Secret that does not match SHADE_PROXY_SECRET …). Anyone else who sends these headers without the secret is ignored the same way, and modules never see the secret.

To change the secret, set the new one on SHADE and in the Worker at about the same time; in between, visitors are counted together for a moment, nothing fails.

Cloudflare's limits

  • Files: 20,000 per deploy on the free plan, 100,000 on a paid plan; 25 MiB per file. Media is part of the build, so a large media library counts here.
  • Redirects (_redirects): Cloudflare allows 2,000 rules and 1,000 characters a line. Each redirect takes a rule for its path with and without the trailing slash, so at most 1,000 redirects; past that the build leaves the rest out with a warning, and their old paths keep the page that sends the browser on. A redirect always wins over a file at its path.
  • Headers (_headers): 100 rules; the build writes four. They reach the static files only, so the Worker adds the same security headers to its own answers.
  • Builds: see Building on the host's builders below.

Netlify

  • Headers (_headers): the same file as Cloudflare's. Netlify's own Cache-Control for pages is the same public, max-age=0, must-revalidate.
  • Redirects (_redirects): one line per redirect, forced (301!), because Netlify otherwise serves the file at the old path. Netlify matches the path with and without the trailing slash.
  • Not found: a rule per language (/en/* /en/404.html 404) after the redirects; other paths get /404.html.
  • Forwarding (an Edge Function, .netlify/v1/edge-functions/shade-forward.js in the site's root): Netlify's proxy rules cannot pass the visitor's address safely, so the build writes an Edge Function instead, and _redirects has no proxy rules. It is declared for /api/v1/account/* and /_server-islands/* only (those whose address is set); every other request is a static file without it. It is the same code as the Cloudflare Worker's forwarding and does the same (Netlify's own X-Nf-* headers dropped too); islands are answered private, no-store. The visitor's address is Netlify's context.ip, never a header the visitor sent. Netlify's _headers does not reach an Edge Function's answers, so the function adds the security headers itself. With the forwarding, personal data passes through Netlify, a US company, as with Cloudflare's forwarding.

Build with the two addresses the forwarding goes to:

SHADE_API_URL=https://admin.example.com SHADE_API_TOKEN=… \
SHADE_ACCOUNT_URL=https://www.example.com ASTRO_KEY=… \
SHADE_STATIC_HOST=netlify \
ACCOUNT_API_URL=https://admin.example.com SITE_SERVER_URL=https://preview.example.com \
pnpm --filter @shadestack/site build
  • ACCOUNT_API_URL: where /api/v1/account/* goes (the API's public role). SITE_SERVER_URL: where /_server-islands/* goes (the site's Node server). Only their scheme, host and port are used. Without SITE_SERVER_URL, personal parts keep their placeholder and the rest of the site works.
  • SHADE_ACCOUNT_URL is the site's own address, so forms post to the site's domain; ASTRO_KEY is the same as the Node server's (Setting up an instance, Site (static) and preview).

The folder to upload is site/dist/client. The build also writes site/.netlify/v1/edge-functions/shade-forward.js, in the site's root (Netlify's base directory), not in the uploaded folder, because Netlify picks up generated Edge Functions from .netlify/v1/edge-functions/ there. A build without ACCOUNT_API_URL and SITE_SERVER_URL removes it. Keep .netlify out of the site's repository (add it to .gitignore): it is build output.

The visitor's address on Netlify

The Edge Function calls the API from Netlify's addresses. As with Cloudflare's forwarding, a shared secret lets SHADE count each visitor:

  1. Make a secret of at least 32 characters (openssl rand -base64 48) and set it as SHADE_PROXY_SECRET on SHADE's public role.
  2. In the Netlify site, add SHADE_PROXY_SECRET under Site configuration, Environment variables (or with netlify env:set), with a scope that includes Functions. Netlify gives Edge Functions only variables set there; one set in netlify.toml does not reach them.
  3. Deploy again: an Edge Function gets the variables as they were at its deploy.

The function reads the secret when a request comes in (Netlify.env.get('SHADE_PROXY_SECRET')); it is never written into the function's file or any file of the build. It sends it to the account API only, with the visitor's address from context.ip. A wrong or missing secret does not break the site.

Building on the host's builders, or uploading

Cloudflare's and Netlify's builders install the site's dependencies from npm. The site depends on SHADE's packages (@shadestack/astro, @shadestack/cloudflare, @shadestack/core, @shadestack/client, @shadestack/module-sdk), which are not on npm yet: they come with the release pipeline (Roadmap). Until then, build the site where the SHADE workspace is (your machine, or a runner of your own) and upload:

cd site && pnpm exec wrangler deploy
cd site && npx netlify deploy --prod --no-build --dir dist/client

wrangler deploy reads the site's wrangler.jsonc: it bundles the Worker and uploads it with the build's files. Run netlify deploy from the site's folder, the base directory, so it finds .netlify/v1/edge-functions/ there. It bundles the Edge Function and uploads it with the files. --no-build keeps it from building the site again.

To rebuild on every publish, the website module's Build hook URL points at whatever runs that build and upload, such as a job on your own runner that a webhook starts, with the build's token (SHADE_API_TOKEN) and SHADE_ISLAND_SECRET as that runner's secrets. The host's own build can do it once every package the site uses is on npm (the website module's isn't yet): Cloudflare's and Netlify's deploy hooks are build hooks SHADE can call directly, with the same two values as the host's build secrets. Check your plan's builds per month on the host before pointing every publish at it.

With a deploy hook as the build hook:

  • Paste the hook's address (https://api.cloudflare.com/…/deploy_hooks/… or https://api.netlify.com/build_hooks/…) as the website module's Build hook URL. Its path is the secret: the setting is kept encrypted and never shown again. SHADE calls it with an empty POST once per rebuild, waits 10 seconds at most and follows no redirect.
  • The Builds screen shows each call as Sent to the builder once the host accepted it. The host's build does not report back to SHADE, so the card stops waiting after 15 minutes; the host's own dashboard shows whether the build worked. A refused or unreachable hook shows as failed, with the reason (Builds).
  • The site's calls are kept in SHADE's build hook log with any other frontends' calls, for 90 days by default (Settings → Data retention, "Build hook log").
  • With no report, a cache listed in SHADE in front of the site is never cleared after a build (CDN caches). Cloudflare and Netlify serve a deploy's new files at once, so the host itself needs no such cache in SHADE.

Privacy: what passes through the host

Whatever the setup, the host sees every visitor's address and the pages they ask for, as any web host does. Beyond that:

Cloudflare (default)Cloudflare (forwarding on)Netlify
Forms, sign-in, accountsstraight to your instancethrough Cloudflarethrough Netlify (forwarding)
Personal parts of pagesstraight from your instancestraight from your instancethrough Netlify from your Node server
The sign-in cookienever sent to Cloudflaresent to Cloudflaresent to Netlify

Cloudflare and Netlify are US companies, so personal data that passes through them leaves the EU. With Cloudflare's default, the host gets no personal data beyond the visitor's address. With forwarding, or on Netlify, name the host as a processor in the site's privacy statement, and have its data processing agreement in place.

What a static host cannot do (yet)

  • Realtime updates on Netlify. Netlify documents a 40-second limit for an Edge Function's answer to start and does not document how long a streamed answer may stay open. Whether a module's live route (text/event-stream) stays open through the Edge Function is not tested yet; the event stream reconnects by itself when it is closed.
  • More than 1,000 redirects on Cloudflare: see above (Cloudflare's Bulk Redirects can hold more, set up outside the build).
  • The Server header: Caddy removes it; neither host lets a site do that.
  • The preview stays on the Node server's own address, as with the static Caddy image.