Skip to content

SV1: the app on Workers - #2

Merged
ruehowl merged 1 commit into
mainfrom
sv/1-the-app
Oct 28, 2026
Merged

ruehowl merged 1 commit into
mainfrom
sv/1-the-app

Conversation

@ruehowl

@ruehowl ruehowl commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

CMSaasStarter (scosman/CMSaasStarter at 2e61406, MIT, its LICENSE kept) now lives in apps/web and runs on Cloudflare Workers + Static Assets.

What changes for Workers

  • Adapter: adapter-auto → @sveltejs/adapter-cloudflare 7, for SvelteKit 2. The build is one Worker, with the pre-rendered marketing pages, blog, sitemap, search index and hashed assets beside it. It is 487 KiB gzipped.
  • Per-environment config: wrangler.template.jsonc renders per environment from the supabase root's wiring document, which carries the project URL and anon key as vars. The fixture render is committed.
  • One project for browser and Worker: tooling/wire/with-vars.mjs hands the rendered vars to vite build, so $env/static/public inlines the same project the Worker talks to.
  • Secrets at request time: $env/static/private → $env/dynamic/private. That covers the service-role key and the Stripe and Resend keys. They are optional Orun secrets that the build pushes to the Worker as secrets (worker-secrets.mjs), and none of them reaches the build.
  • Stripe is optional and talks over fetch: without a key, the billing page says to connect it, and checkout and the portal send the visitor there.
  • Precompiled email templates: Workers forbid code generation, which handlebars.compile does. A Vite plugin precompiles the templates at build, and the Handlebars runtime renders them.
  • /api/health: counts the profiles table with the service-role key. This is the deploy's smoke.
  • Smaller changes:
    • WebsiteBaseUrl comes from PUBLIC_SITE_URL.
    • The welcome email is sent from the owner's own sender.
    • OAuth providers start empty; each needs an OAuth app in the project first.
  • Dependencies:
    • fuse.js and prettier stay on the versions upstream's lockfile resolved. Newer ones break the search page's types and re-format upstream's files.
    • patch-package is gone: the SvelteKit bug it patched does not reproduce on 2.70.

Tests

tests/web checks that:

  • the committed wrangler.jsonc is the fixture render;
  • no secret is read through $env/static/private;
  • every secret goes to the Worker and none reaches the build.

It then runs the app's own suite: upstream's tests plus the port's (Stripe unconnected, the precompiled templates, /api/health, billing without Stripe).

Locally:

  • Install, wire:fixture, typecheck, lint, test (6 + 19) and build are all green.
  • wrangler dev over the build serves every page, the RSS feed, the sitemap and the search index. It sends /account to /login and 404s an unknown path.

Generated by Claude Code

CMSaasStarter (scosman/CMSaasStarter at 2e61406, MIT, its LICENSE kept) in
apps/web, on Cloudflare Workers + Static Assets:

- adapter-auto → @sveltejs/adapter-cloudflare 7 (SvelteKit 2): one Worker
  with the pre-rendered marketing pages, the blog, the sitemap, the search
  index and the hashed assets beside it; 487 KiB gzipped.
- wrangler.template.jsonc renders per environment from the supabase root's
  wiring document (the project's URL and anon key as vars); the fixture render
  is committed. tooling/wire/with-vars.mjs hands those vars to `vite build`, so
  $env/static/public inlines the same project the Worker talks to.
- Every secret is read at request time through $env/dynamic/private instead
  of being inlined by $env/static/private: the service-role key, Stripe's and
  Resend's keys. component.yaml resolves them as optional Orun secrets and the
  build pushes each set one to the Worker as a secret (worker-secrets.mjs),
  never into the build.
- Stripe is optional and talks over fetch: without a key the billing page says
  to connect it and checkout and the portal send the visitor there.
- Workers forbid code generation, so the email templates are precompiled at
  build (a Vite plugin) and rendered with the Handlebars runtime alone.
- /api/health counts the profiles table with the service-role key: the deploy's
  smoke, proving the project, its key and its schema reached the Worker.
- WebsiteBaseUrl comes from PUBLIC_SITE_URL (SITE_URL or the workers.dev URL);
  the welcome email is sent from the owner's own sender; OAuth providers start
  empty (each needs an OAuth app in the project first).
- fuse.js and prettier stay on the versions upstream's lockfile resolved
  (newer ones break the search page's types and re-format upstream's files);
  patch-package is gone (the SvelteKit bug it patched does not reproduce on
  2.70).

tests/web holds the Worker's config to its fixture render and its secrets to
the Worker, then runs the app's own suite (upstream's tests and the port's).
Locally: install, wire:fixture, typecheck, lint, test (6 + 19) and build
green; wrangler dev over the build serves every page, the feed, the sitemap
and the search index, sends /account to /login, and 404s an unknown path.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019PcpNVpFBcbeiX3EHdXfmn
@ruehowl
ruehowl merged commit b266c8f into main Oct 28, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants