diff --git a/.env.example b/.env.example index d131456..5fdd8a8 100644 --- a/.env.example +++ b/.env.example @@ -30,6 +30,16 @@ EMAIL_FROM_NAME=Eva Shafik # Timezone used for booking times in emails (IANA name) SITE_TIMEZONE=Europe/Oslo +# Public URLs the browser uses: ://admin.. +# They must match the address bar exactly (SvelteKit's form CSRF check). +# Local default: http + :8080. Behind a reverse proxy / TLS on 443, e.g.: +# URL_SCHEME=https +# URL_PORT= +# (empty URL_PORT = no port in the URL; leave the line out to get :8080) +DOMAIN=localhost +URL_SCHEME=http +URL_PORT=:8080 + # Caddy scheme for the reverse proxy on port 8080. # http (default) — plain HTTP; matches the ORIGIN vars in docker-compose.yml # https — HTTPS on :8080 (self-signed unless you add a cert issuer; diff --git a/AGENTS.md b/AGENTS.md index 60af89e..d9281ce 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -173,10 +173,11 @@ cd app-public && npm run build ## Environment - `DOMAIN` — base domain for subdomain routing. Defaults to `localhost` for local dev. Set in `docker-compose.yml` or `.env`. -- `PUBLIC_POCKETBASE_URL` — public-facing PocketBase URL (`http://db.${DOMAIN}:8080`). Set in `docker-compose.yml`. +- `URL_SCHEME` (default `http`), `URL_PORT` (default `:8080`; set it empty for no port) — build every browser-facing URL below as `://.`. They must match the address bar exactly: a mismatched `ORIGIN` makes SvelteKit reject form POSTs (admin login) with "Cross-site POST form submissions are forbidden". Behind a TLS reverse proxy: `URL_SCHEME=https`, `URL_PORT=`. (podman-compose 1.5 can't do nested `${A:-${B}}` defaults, hence two flat variables.) +- `PUBLIC_POCKETBASE_URL` — public-facing PocketBase URL (`://db.${DOMAIN}`). Set in `docker-compose.yml`. - `POCKETBASE_INTERNAL_URL` — internal Docker network URL (`http://pocketbase:80`). Set in `docker-compose.yml`. -- `ORIGIN` — SvelteKit origin for SSR. Differs per app: `http://admin.${DOMAIN}:8080` (admin), `http://www.${DOMAIN}:8080` (public). -- `PUBLIC_SITE_URL` — public site URL used by the admin app for cross-subdomain preview links (`http://www.${DOMAIN}:8080`). +- `ORIGIN` — SvelteKit origin for SSR. Differs per app: `://admin.${DOMAIN}` (admin), `://www.${DOMAIN}` (public). +- `PUBLIC_SITE_URL` — public site URL used by the admin app for cross-subdomain preview links (`://www.${DOMAIN}`). - `SMTP_HOST`, `SMTP_PORT`, `SMTP_USER`, `SMTP_PASS`, `EMAIL_FROM`, `EMAIL_FROM_NAME` — Brevo SMTP relay for booking emails (both apps). Empty `SMTP_HOST` = log emails instead of sending. - `SITE_TIMEZONE` — IANA timezone for booking times in emails (default `Europe/Oslo`). - Secrets (Stripe, `INTERNAL_API_SECRET`, SMTP) are read from a root-level `.env` next to `docker-compose.yml`; see `.env.example`. diff --git a/README.md b/README.md index 9491e5d..60e87fe 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,17 @@ The project runs exclusively through Docker Compose. There is no bare host dev m Caddy's `.localhost` handling works without DNS or hosts-file changes. Source changes require rebuilding (`docker compose up --build`); the containers run the production build (`node build`), not a dev server. +**Deploying behind HTTPS** (e.g. another reverse proxy terminating TLS and forwarding to `:8080`): the apps must know the URL the browser really uses, or the admin login fails with *"Cross-site POST form submissions are forbidden"*. In `.env`: + +```sh +DOMAIN=example.com # → admin.example.com, www.example.com, db.example.com +URL_SCHEME=https +URL_PORT= # empty: no port in the URL +CADDY_SCHEME=http # this stack's Caddy stays plain HTTP behind the TLS proxy +``` + +Then `docker compose up -d` (no rebuild needed: these are runtime env vars). + ## Docker Compose Run the full stack: diff --git a/docker-compose.yml b/docker-compose.yml index a7b0682..881482d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -34,9 +34,12 @@ services: environment: PORT: 3001 POCKETBASE_INTERNAL_URL: http://pocketbase:80 - PUBLIC_POCKETBASE_URL: http://db.${DOMAIN:-localhost}:8080 - ORIGIN: http://admin.${DOMAIN:-localhost}:8080 - PUBLIC_SITE_URL: http://www.${DOMAIN:-localhost}:8080 + # Browser-facing URLs. They must match the address bar exactly, or + # SvelteKit rejects logins/forms ("Cross-site POST form submissions are + # forbidden"). Behind a TLS proxy: URL_SCHEME=https and URL_PORT= (empty). + PUBLIC_POCKETBASE_URL: ${URL_SCHEME:-http}://db.${DOMAIN:-localhost}${URL_PORT-:8080} + ORIGIN: ${URL_SCHEME:-http}://admin.${DOMAIN:-localhost}${URL_PORT-:8080} + PUBLIC_SITE_URL: ${URL_SCHEME:-http}://www.${DOMAIN:-localhost}${URL_PORT-:8080} BODY_SIZE_LIMIT: 52428800 # 50MB — import payload embeds all images as base64 STRIPE_CURRENCY: ${STRIPE_CURRENCY:-eur} # Booking emails (Brevo SMTP relay) — admin needs these for resend/test sends @@ -62,8 +65,8 @@ services: environment: PORT: 3000 POCKETBASE_INTERNAL_URL: http://pocketbase:80 - PUBLIC_POCKETBASE_URL: http://db.${DOMAIN:-localhost}:8080 - ORIGIN: http://www.${DOMAIN:-localhost}:8080 + PUBLIC_POCKETBASE_URL: ${URL_SCHEME:-http}://db.${DOMAIN:-localhost}${URL_PORT-:8080} + ORIGIN: ${URL_SCHEME:-http}://www.${DOMAIN:-localhost}${URL_PORT-:8080} # No PocketBase or Stripe secrets here: shop writes happen in PocketBase # (pb_hooks/shop). The publishable key is public by design. PUBLIC_STRIPE_PUBLISHABLE_KEY: ${PUBLIC_STRIPE_PUBLISHABLE_KEY:-}