Skip to content

New Astro Site

Requires a deployed CMS (setup) or one running locally.

Terminal window
npm create @kenresoft-cms@latest my-site -- --astro
cd my-site
cp .env.example .env
pnpm install
pnpm dev

Set your CMS API URL in .env:

PUBLIC_KENRESOFT_CMS_URL=https://your-cms-api.example.com

The default is http://localhost:8787, which is where wrangler dev serves the API locally.

This copies a template bundled inside @kenresoft-cms/create (it does not clone the CMS) and starts a fresh Git repository with no shared history. It is a one-time starter, the same as npm create astro@latest: nothing updates it afterwards, and pnpm run update in the CMS never touches it.

The starter uses @kenresoft-cms/astro (the newest version at scaffold time) and @astrojs/cloudflare with output: 'server'. It includes:

  • src/lib/cms.ts: a public-content client and cmsForRequest(request) for server-side session checks.
  • src/lib/browser-cms.ts: browserCms, a client that talks to your own /cms proxy from the browser.
  • src/middleware.ts: a per-request client bound to Live Preview tokens (Astro.locals.cms).
  • src/pages/cms/[...path].ts: the same-origin proxy.
  • src/pages/blog/, src/pages/contact.astro: examples against a blog-post content type and a contact form. Change the slugs and field names to match your CMS.
  • src/pages/account/: register, sign in, verify email, forgot and reset password, and a protected account page (with two-factor and optional Turnstile).
  • wrangler.jsonc with the global_fetch_strictly_public flag.

It is content-agnostic. It does not assume Commerce or any specific content model.

  1. Add the site’s origin to the CMS API’s CORS_ORIGINS.
  2. Configure real email on the CMS. Accounts must verify their email before signing in.
  3. Recommended: set the same TRUSTED_PROXY_SECRET on the CMS and on this site. See Same-origin proxy.
  4. Optional bot protection: create a Turnstile widget at dash.cloudflare.com → Turnstile, set it up on the API with pnpm run update -- --turnstile, and set PUBLIC_TURNSTILE_SITE_KEY here to the widget’s site key. Both halves are required; the register page has no widget without the site key, even with the secret set on the API. On a Cloudflare Git build, add it as a build variable, the same way as PUBLIC_KENRESOFT_CMS_URL (see Deploying and updating Astro).

See Authentication and CORS if sign-in fails.