Skip to content

Panel on Cloudflare Pages ​

The panel is static files. You can serve it from Cloudflare Pages and keep bs-control as the API only. One build works anywhere: the panel reads config.json at start to find the API.

Before you start ​

  • Pick two hosts on the same domain, for example panel.example.com (Pages) and api.example.com (control). Not *.pages.dev: it is another site, and sign in would break on reload.
  • Both on https.

1. Allow the panel origin on the control ​

bash
# /opt/bitstream/etc/control.env
BS_HTTP_SPA_ORIGINS=https://panel.example.com

Restart: sudo systemctl restart bs-control. A listed origin on another site gets 403 cross_site_panel.

2. Build ​

bash
cd web
pnpm install
pnpm build

Write the runtime config and the headers into dist/:

bash
API_ORIGIN=https://api.example.com node scripts/pages-files.mjs

This writes:

  • dist/config.json: { "apiBase": "https://api.example.com/api/v1" }.
  • dist/_headers: a strict Content-Security-Policy that allows scripts only from the panel (inline theme script by hash) and API calls to your API origin, plus X-Frame-Options, Referrer-Policy and long caching for /assets/*.

Pages serves index.html for unknown paths when there is no 404.html, so panel routes work after a reload.

3. Deploy ​

With Wrangler:

bash
npx wrangler pages deploy dist --project-name bitstream-panel

Or with Git integration: build command pnpm install && pnpm build && node scripts/pages-files.mjs, output folder web/dist, root web, and the variable API_ORIGIN=https://api.example.com.

Then in Pages, Custom domains, add panel.example.com.

4. Save the plan ​

In the panel, Settings, Domains: panel served on a static host, admin panel panel.example.com, admin API api.example.com. The DNS button skips the panel record (Pages gives you that CNAME) and creates the API record.

Check ​

  • Sign in, press F5: you stay signed in.
  • In the browser console, no CSP errors.
  • curl -I https://api.example.com/api/v1/setup/status -H 'Origin: https://panel.example.com' shows Access-Control-Allow-Origin: https://panel.example.com.

Bitstream documentation