Compare commits

..

2 commits

Author SHA1 Message Date
13b5f2bbcb Merge pull request 'Fix admin login behind HTTPS: configurable public URL scheme/port' (#2) from session/polish into main
Reviewed-on: #2
2026-10-07 16:43:41 +02:00
7b6c8c2511 Compose: configurable public URL scheme/port (fixes login behind HTTPS)
ORIGIN, PUBLIC_POCKETBASE_URL and PUBLIC_SITE_URL were hard-coded to
http://<sub>.${DOMAIN}:8080. Behind a TLS reverse proxy the browser's
origin is https://<sub>.<domain>, so SvelteKit rejected the admin login
form ("Cross-site POST form submissions are forbidden") and image URLs
pointed at an unreachable port. URL_SCHEME / URL_PORT now build them
(defaults unchanged). Two flat variables because podman-compose 1.5 does
not support nested ${A:-${B}} defaults.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KgF3Kf47LjPGHKQHszpUAv
2026-10-07 14:37:28 +00:00
4 changed files with 33 additions and 8 deletions

View file

@ -30,6 +30,16 @@ EMAIL_FROM_NAME=Eva Shafik
# Timezone used for booking times in emails (IANA name) # Timezone used for booking times in emails (IANA name)
SITE_TIMEZONE=Europe/Oslo SITE_TIMEZONE=Europe/Oslo
# Public URLs the browser uses: <URL_SCHEME>://admin.<DOMAIN><URL_PORT>.
# 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. # Caddy scheme for the reverse proxy on port 8080.
# http (default) — plain HTTP; matches the ORIGIN vars in docker-compose.yml # http (default) — plain HTTP; matches the ORIGIN vars in docker-compose.yml
# https — HTTPS on :8080 (self-signed unless you add a cert issuer; # https — HTTPS on :8080 (self-signed unless you add a cert issuer;

View file

@ -173,10 +173,11 @@ cd app-public && npm run build
## Environment ## Environment
- `DOMAIN` — base domain for subdomain routing. Defaults to `localhost` for local dev. Set in `docker-compose.yml` or `.env`. - `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 `<scheme>://<sub>.<DOMAIN><port>`. 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 (`<scheme>://db.${DOMAIN}<port>`). Set in `docker-compose.yml`.
- `POCKETBASE_INTERNAL_URL` — internal Docker network URL (`http://pocketbase:80`). 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). - `ORIGIN` — SvelteKit origin for SSR. Differs per app: `<scheme>://admin.${DOMAIN}<port>` (admin), `<scheme>://www.${DOMAIN}<port>` (public).
- `PUBLIC_SITE_URL` — public site URL used by the admin app for cross-subdomain preview links (`http://www.${DOMAIN}:8080`). - `PUBLIC_SITE_URL` — public site URL used by the admin app for cross-subdomain preview links (`<scheme>://www.${DOMAIN}<port>`).
- `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. - `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`). - `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`. - Secrets (Stripe, `INTERNAL_API_SECRET`, SMTP) are read from a root-level `.env` next to `docker-compose.yml`; see `.env.example`.

View file

@ -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. 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 ## Docker Compose
Run the full stack: Run the full stack:

View file

@ -34,9 +34,12 @@ services:
environment: environment:
PORT: 3001 PORT: 3001
POCKETBASE_INTERNAL_URL: http://pocketbase:80 POCKETBASE_INTERNAL_URL: http://pocketbase:80
PUBLIC_POCKETBASE_URL: http://db.${DOMAIN:-localhost}:8080 # Browser-facing URLs. They must match the address bar exactly, or
ORIGIN: http://admin.${DOMAIN:-localhost}:8080 # SvelteKit rejects logins/forms ("Cross-site POST form submissions are
PUBLIC_SITE_URL: http://www.${DOMAIN:-localhost}:8080 # 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 BODY_SIZE_LIMIT: 52428800 # 50MB — import payload embeds all images as base64
STRIPE_CURRENCY: ${STRIPE_CURRENCY:-eur} STRIPE_CURRENCY: ${STRIPE_CURRENCY:-eur}
# Booking emails (Brevo SMTP relay) — admin needs these for resend/test sends # Booking emails (Brevo SMTP relay) — admin needs these for resend/test sends
@ -62,8 +65,8 @@ services:
environment: environment:
PORT: 3000 PORT: 3000
POCKETBASE_INTERNAL_URL: http://pocketbase:80 POCKETBASE_INTERNAL_URL: http://pocketbase:80
PUBLIC_POCKETBASE_URL: http://db.${DOMAIN:-localhost}:8080 PUBLIC_POCKETBASE_URL: ${URL_SCHEME:-http}://db.${DOMAIN:-localhost}${URL_PORT-:8080}
ORIGIN: http://www.${DOMAIN:-localhost}:8080 ORIGIN: ${URL_SCHEME:-http}://www.${DOMAIN:-localhost}${URL_PORT-:8080}
# No PocketBase or Stripe secrets here: shop writes happen in PocketBase # No PocketBase or Stripe secrets here: shop writes happen in PocketBase
# (pb_hooks/shop). The publishable key is public by design. # (pb_hooks/shop). The publishable key is public by design.
PUBLIC_STRIPE_PUBLISHABLE_KEY: ${PUBLIC_STRIPE_PUBLISHABLE_KEY:-} PUBLIC_STRIPE_PUBLISHABLE_KEY: ${PUBLIC_STRIPE_PUBLISHABLE_KEY:-}