diff --git a/CHANGELOG.md b/CHANGELOG.md index 05dd439f..44caca9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ Versions follow [Semantic Versioning](https://semver.org/). ## [Unreleased] +### Changed (development environment, 2026-10-13) + +- **DEV on the private network** — the owner tests from other devices: the DEV origin (the machine's LAN address, `FAUNOSTEO_DEV_HOST`, detected or set) lives in `scripts/dev-env.sh`; `pnpm dev` serves the app on that origin wired to the local stack, `pnpm dev:offline` keeps the local tool alone; every Supabase CLI call goes through `scripts/supabase.sh` so `config.toml` (API external URL for the mail links, site URL, Studio API URL via `env()`) follows the origin; private-network redirect URLs for the PKCE links. Identity recorded: Faunosteo, https://faunosteo.com; environments DEV / STAGING / PROD and the exposure table in `docs/development/ENVIRONMENTS.md`. + ### Added (SaaS migration, plan Step 8 = Rust R1) - **Files foundation and profile photo (Step 8)** — `public.assets` as the authority over user files (status, owner, server-built keys, worker lease token), seven private Storage buckets (only `avatars` open, through SELECT / INSERT policies evaluated on `assets`; the six others closed until their step), a quarantine upload path (`begin_avatar_upload` → direct upload at the quarantine key → `confirm_asset_upload`), a deferred purge queue (48 h for a replaced or removed avatar, 1 h for quarantine and rejected uploads: the backup invariant) and the audited RPCs of the browser and of the worker (migration `20261013100000`, pgTAP 010 with 125 allowed and denied checks, policy census). **Rust worker job loop** (`crates/worker`, R1): the keyed parent claims leased jobs through PostgREST, downloads the quarantine bytes, hands them to the sandboxed `decode` child of R0 (empty environment, rlimits, seccomp allowlist unchanged), uploads the 512 × 512 lossy WebP, commits the row, deletes the quarantine object, rejects with closed codes (`unsupported_type`, `decode_failed`, `dimensions`, `processing_error`), sweeps expired uploads, the purge queue and quarantine leftovers; JSON line logs with a field allowlist; per-stage watchdog; Compose service `worker` (profile `worker`, read-only, no capability, external Supabase network, `.env.worker`). **Profile photo** in Mon compte (preview before any request, save, processing with polling, rejection messages, replacement, removal with confirmation) and in the sidebar, the mobile drawer and the top bar (name beside it on desktop, link to Mon compte); JPEG / PNG / WebP only, never SVG, downscaled to 1024 px in the browser as transport, judged again by the worker; the owner downloads the clean object under RLS (no signed URL). Real-stack end-to-end run `pnpm e2e:avatar`. Spec: `docs/development/STORAGE.md`. diff --git a/CLAUDE.md b/CLAUDE.md index 19d3adf6..5ca48313 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -7,6 +7,8 @@ ## Project overview +**Faunosteo** is the official, final product name (the SaaS, the application, the public site and its services); official domain **https://faunosteo.com** (production, separate VPS, the site present there is preserved until an explicit migration decision). Never propose another brand name; keep the logo, palette and validated mockups. Environments DEV / STAGING (`staging.faunosteo.com`, planned, not created) / PROD are isolated (`docs/development/ENVIRONMENTS.md`). + Single-praticien French web app for veterinary osteopathy bilans on animal anatomy SVGs. Practitioner clicks anatomical zones, builds observations with pathologies/severity, writes conclusion, and exports an A4 PDF. PDF carries the full JSON state as a native @@ -71,8 +73,9 @@ access layer (see `docs/development/WORKSPACE.md`). Every command below runs from the repository root and delegates to the packages. ```bash -# Development -pnpm dev +# Development (DEV origin = this machine's LAN address, scripts/dev-env.sh; tests run from other devices) +pnpm dev # Vite on http://:5173 wired to the local stack (needs pnpm db:start) +pnpm dev:offline # the local tool without backend # Production build (typecheck + vite build) pnpm build @@ -95,8 +98,9 @@ pnpm lint # Format pnpm format -# Supabase local stack (Docker) — docs/development/SUPABASE.md -pnpm db:start # start stack, apply migrations + seed +# Supabase local stack (Docker) — docs/development/SUPABASE.md; every CLI call goes through +# scripts/supabase.sh (exports the DEV origin that config.toml reads with env()); `pnpm supabase ` +pnpm db:start # start stack, apply migrations + seed; FAUNOSTEO_DEV_HOST= to pick another address pnpm db:reset # replay from zero pnpm db:test # pgTAP on the real stack pnpm db:types # regenerate packages/supabase/src/database.types.ts @@ -271,6 +275,7 @@ faunosteo/ │ ├─ wasm/ ← faunosteo-wasm: wasm-bindgen facade (core_version, call, R0 trap proofs) │ └─ worker/ ← faunosteo-worker: plain main; `decode` sandboxed child (rlimits, seccomp allowlist, image → libwebp), parent Spawner + RIFF check; R1 `run` loop: config, log (JSON lines, allowlist), keys, backend trait + http (ureq, PostgREST rpc + Storage objects), job, sweep, watchdog; Dockerfile, scripts/derive-seccomp.sh ├─ scripts/{rust-env,rust-check,wasm-build,check-all,avatar-e2e}.sh ← native Rust gate, wasm build, the pre-merge gate (`pnpm check:all`), the real-stack avatar e2e +├─ scripts/{dev-env,supabase,dev}.sh ← the DEV origin (LAN address) in one place; CLI wrapper; `pnpm dev` on that origin ├─ docker-compose.yml ← `app` service; `worker` service under the `worker` profile (read-only, cap_drop ALL, external Supabase network, `.env.worker`) ├─ docker/rust-builder.Dockerfile, rust-run.sh, csp-proof/ ← reproducible Rust builder (alternative) + the CSP proof ├─ .gitea/workflows/ci.yml ← PREPARED, never executed (no runner): rust job (builder image, scripts/rust-check.sh, types drift, wasm), install, typecheck, test, lint, build, docker (app + worker test stage + runtime) @@ -433,6 +438,16 @@ Database (Supabase) operator scripts under `packages/*/scripts/` read it from the environment and are never bundled. - pgTAP files run on PGlite and on the real image: scope counts to fixture ids, pin `collate "C"` on text ordering. +### Environments and LAN access (docs/development/ENVIRONMENTS.md) +- The owner tests from other devices of the private network, never on the Ubuntu machine: every test surface + (app, Supabase API, Mailpit, Studio) is addressed by the DEV origin (`scripts/dev-env.sh`, `FAUNOSTEO_DEV_HOST`), + never by `127.0.0.1` / `localhost`, never hard-coded in a source. The Supabase CLI runs only through + `scripts/supabase.sh` (`pnpm db:*`, `pnpm supabase`): config.toml reads the origin with `env()`. +- Exposure: 5173 and 54321 are what a remote browser needs; Studio 54323 and Mailpit 54324 are unauthenticated + admin tools for the private subnet only; PostgreSQL 54322 should not be reachable from the LAN (firewall = + owner decision); the worker publishes no port. Nothing is exposed to the Internet; no production infrastructure + is touched from this repository. Rust is built natively; Docker runs services, the worker, sandbox tests and images. + ### Files and Storage (migration 20261013100000, docs/development/STORAGE.md) - `public.assets` is the authority over every user file: status, owner, keys, lease. Every write is an RPC; the browser reads its own rows through an explicit column list (`select=*` is refused: lease columns are not granted). diff --git a/README.md b/README.md index 70d57f92..ec2aa917 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,11 @@ cp .env.example .env # edit APP_* vars if desired pnpm dev # http://localhost:5173 ``` +Development server on the private network (the DEV origin is the machine's +LAN address, `scripts/dev-env.sh`): `pnpm db:start`, then `pnpm dev` and open +`http://:5173` from any device of the network; Mailpit for the +sign-up mails on `:54324` (`docs/development/ENVIRONMENTS.md`). + Rust (core, browser module, worker): a user-level `rustup` installs the pinned toolchain from `rust-toolchain.toml` on first use; see `docs/development/RUST.md` §1 for the three `cargo install` / `rustup diff --git a/docs/development/ENVIRONMENTS.md b/docs/development/ENVIRONMENTS.md new file mode 100644 index 00000000..d256be81 --- /dev/null +++ b/docs/development/ENVIRONMENTS.md @@ -0,0 +1,107 @@ +# Environments: DEV, STAGING, PROD + +Owner decisions of 2026-10-13 (BDR-049). Product identity: **Faunosteo**, +official domain **https://faunosteo.com** (the SaaS, the application, the +public site and its services; the current logo, palette and validated +mockups under `docs/design/` stay). No other brand name is proposed again. + +| Environment | Where | Data | Reachable from | +|---|---|---|---| +| **DEV** | the self-hosted Ubuntu development machine (native Rust via rustup/Cargo, Node/Vite, Docker rootless for the Supabase stack, the worker and the images) | test data, fictitious accounts, local Supabase, local worker | the owner's other devices on the private network (computer, phone): the DEV origin below | +| **STAGING** | `staging.faunosteo.com`, planned, not created | its own database, storage, secrets, accounts | later | +| **PROD** | `https://faunosteo.com`, separate VPS | real data | the Internet; the site present today is preserved until an explicit migration decision | + +Isolation: each environment keeps its own PostgreSQL, Storage, secrets, +accounts, OAuth client ids, payments, e-mails, professional files and +bilans. Production data is never copied into DEV. A merge into `develop` +never deploys anything; no CI/CD runs on the forge today (workflow files are +prepared material), no runner, registry or secret exists. + +## 1. Rule: every test surface of DEV is reachable on the private network + +The owner does not test on the Ubuntu machine itself. Whatever a browser or +a phone needs for a test is addressed by the machine's LAN address (or a +private DNS name), never by `127.0.0.1` or `localhost` of the server, and +never hard-coded in the sources. + +## 2. The DEV origin, in one place + +`scripts/dev-env.sh` decides the DEV host once: + +| Variable | Default | Meaning | +|---|---|---| +| `FAUNOSTEO_DEV_HOST` | the first non-loopback IPv4 of the host (`hostname -I`) | address or name of this machine on the private network; `127.0.0.1` for a host-only session; a production host is refused | +| derived | `FAUNOSTEO_DEV_API_URL` `http://:54321`, `FAUNOSTEO_DEV_SITE_URL` `http://:5173`, `FAUNOSTEO_DEV_API_ORIGIN`, `FAUNOSTEO_DEV_STUDIO_URL` `:54323`, `FAUNOSTEO_DEV_MAILPIT_URL` `:54324` | read by `supabase/config.toml` (`env()`) and by the Vite dev server | + +Consumers: `scripts/supabase.sh` (every CLI call: `pnpm supabase …`, +`pnpm db:start|stop|reset|test|types`), `scripts/dev.sh` (`pnpm dev`), +`scripts/avatar-e2e.sh`. The address changes with `FAUNOSTEO_DEV_HOST=…` +in front of the command, without touching a source file. Calling the CLI +binary directly (`node_modules/.bin/supabase start`) leaves the literal +`env(...)` text in the services: always go through `pnpm`. + +```bash +pnpm db:start # stack on the DEV origin; mails link to http://:54321/auth/v1/... +pnpm worker:image && docker compose --profile worker up -d worker # .env.worker: DEPLOY.md +pnpm dev # http://:5173, Supabase by the DEV origin, HMR over the LAN +pnpm dev:offline # the local tool without backend (host:5173 too) +FAUNOSTEO_DEV_HOST=10.0.0.5 pnpm db:start # another address: restart the stack, then pnpm dev again +``` + +`supabase/config.toml` reads: `api.external_url` (the address GoTrue writes +into confirmation and recovery mails), `auth.site_url`, `studio.api_url`; +`auth.additional_redirect_urls` allows every private-network host on `:5173` +(`192.168.*.*`, `10.*.*.*`, `172.16.*.*`) plus the host-only forms, so PKCE +links return to the origin the browser used. + +## 3. What listens where (DEV, measured 2026-10-13) + +The Supabase CLI publishes its ports on every interface (`0.0.0.0`, no bind +option); Vite listens on every interface (`server.host: true`). + +| Service | Port | Interface | Needed by the remote browser | Protection | +|---|---|---|---|---| +| Application (Vite) | 5173 | all | yes | none (dev build, anon key only) | +| Supabase API (Kong: Auth, PostgREST, Storage) | 54321 | all | yes | RLS, policies, the anon key; the service key never reaches a browser | +| Studio | 54323 | all | useful for inspection, not for the flows | **none**: full database access to anyone on the LAN | +| Mailpit | 54324 | all | yes for sign-up and recovery mails | **none**: every DEV mail readable on the LAN | +| PostgreSQL | 54322 | all | no | password `postgres`: **should not be reachable from the LAN** | +| Worker | none | — | no | internal only (Supabase compose network, read-only, no capability) | +| PostgREST, GoTrue, Storage, pg-meta | none | — | behind Kong | — | + +The firewall state of the host could not be read without privileges. The +proposal for the owner (not applied): a host firewall keeping 54322 on +loopback only, and 54323 / 54324 restricted to the private subnet +(`192.168.1.0/24`); 5173 and 54321 open to that subnet. Nothing is exposed to +the Internet by this repository; the box, the router and any public +forwarding stay untouched. + +HTTP on a private address: the auth flows (PKCE, cookies-free session in +localStorage) work; what does not is any browser feature that needs a +secure context on a non-loopback origin (camera, geolocation, some +clipboard and service-worker features) and any OAuth provider that refuses +`http://` redirect URIs. When one of those lands, the answer is a private +HTTPS origin (local CA or a private name with a certificate), never the +production domain. + +## 4. Procedure from another device (owner validation) + +Stack and worker started on the Ubuntu machine (`pnpm db:start`, the worker +container, `pnpm dev`), then from the computer, and again from the phone on +the same network: + +1. `http://:5173/` opens the Faunosteo home. +2. `/login` shows the sign-in card. +3. `alice@faunosteo.local` / `LocalDev-only-password-1` signs in. +4. `/app` shows the dashboard. +5. Mon compte opens. +6. Modifier la photo with a photo of the device → preview → Enregistrer. +7. "Traitement en cours…" then the photo (the worker's log shows + `job_completed`). +8. Reload: the photo is still there, in the circle, the sidebar / drawer and + the top bar. +9. Se déconnecter returns to the home; `/app` redirects to `/login`. +10. Same steps on the phone; no horizontal scroll. + +A sign-up from the device: Mailpit at `http://:54324`, the link opened +in the same browser as the form. diff --git a/docs/development/IDENTITY.md b/docs/development/IDENTITY.md index e03839c7..eee177fe 100644 --- a/docs/development/IDENTITY.md +++ b/docs/development/IDENTITY.md @@ -99,9 +99,8 @@ holding a platform role. ## 5. Manual validation (local stack) ```bash -pnpm db:start # prints API URL + anon key; Mailpit at http://127.0.0.1:54324 -VITE_SUPABASE_URL=http://127.0.0.1:54321 VITE_SUPABASE_ANON_KEY= \ -VITE_AUTH_PROVIDERS=google pnpm dev +pnpm db:start # stack on the DEV origin (LAN address); Mailpit at http://:54324 +VITE_AUTH_PROVIDERS=google pnpm dev # http://:5173 from any device of the private network (ENVIRONMENTS.md) ``` 1. `/app` while signed out → `/login?next=%2Fapp`. The login card shows a diff --git a/docs/development/SUPABASE.md b/docs/development/SUPABASE.md index 192e4467..38b9d0d9 100644 --- a/docs/development/SUPABASE.md +++ b/docs/development/SUPABASE.md @@ -55,6 +55,14 @@ like every other tool. Never install it globally. ## 3. Start, stop, reset +Every CLI call goes through `scripts/supabase.sh` (`pnpm db:*`, `pnpm supabase +`): it exports the DEV origin that `config.toml` reads with `env()` +(`api.external_url`, `auth.site_url`, `studio.api_url`). A direct +`node_modules/.bin/supabase start` would leave the literal `env(...)` text in +GoTrue's mail links. Published ports (all interfaces): API 54321, PostgreSQL +54322, Studio 54323, Mailpit 54324 (`ENVIRONMENTS.md` §3 for what each one +exposes). + ```bash pnpm db:start # supabase start: pulls images, applies migrations + seed, prints URLs and keys pnpm db:stop # supabase stop (keeps the volume) @@ -246,14 +254,19 @@ audit rows (bootstrap with null actor, grant by the owner). ## 9. Wiring the app -`.env` (Docker) or `apps/app/.env.local` (Vite dev): +Development: `pnpm dev` (`scripts/dev.sh`) sets `VITE_SUPABASE_URL` to the DEV +origin (`http://:54321`, the LAN address of the machine: +`ENVIRONMENTS.md` §2) and the anon key from `supabase status`; the app is +served on `http://:5173` for every device of the private network. +`pnpm dev:offline` runs the local tool without backend. Docker deployments use +`.env`: ```bash -APP_SUPABASE_URL=http://127.0.0.1:54321 # VITE_SUPABASE_URL in dev -APP_SUPABASE_ANON_KEY= # VITE_SUPABASE_ANON_KEY in dev +APP_SUPABASE_URL= +APP_SUPABASE_ANON_KEY= # public by design ``` -Both empty (the default) keeps the app in its local-only mode: +Both empty keeps the app in its local-only mode: `getSupabaseClient()` returns null, the auth screens show an "unavailable" notice and `/app` redirects to `/login`. `APP_AUTH_PROVIDERS` / `VITE_AUTH_PROVIDERS` (`google,apple`) lists the OAuth buttons to show. diff --git a/docs/development/WORKSPACE.md b/docs/development/WORKSPACE.md index 2e09f100..2c93df8a 100644 --- a/docs/development/WORKSPACE.md +++ b/docs/development/WORKSPACE.md @@ -85,7 +85,9 @@ works as `corepack pnpm `. | Command | Does | |---|---| | `pnpm install` | installs the whole workspace from the lockfile | -| `pnpm dev` | Vite dev server of `apps/app` on :5173 | +| `pnpm dev` | Vite dev server of `apps/app` on `http://:5173`, wired to the local Supabase stack by the DEV origin (`scripts/dev.sh`, `ENVIRONMENTS.md`) | +| `pnpm dev:offline` | the same server without backend (local tool only) | +| `pnpm supabase ` / `pnpm db:*` | the Supabase CLI with the DEV origin exported (`scripts/supabase.sh`) | | `pnpm preview` | serves `apps/app/dist` on :4173 | | `pnpm typecheck` | `tsc --noEmit` in every package | | `pnpm test:run` | vitest once in every package | diff --git a/package.json b/package.json index b954d381..118b5a81 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,8 @@ "pnpm": ">=10.13 <11" }, "scripts": { - "dev": "pnpm --filter @faunosteo/app dev", - "dev:lan": "bash scripts/dev-lan.sh", + "dev": "bash scripts/dev.sh", + "dev:offline": "pnpm --filter @faunosteo/app dev", "preview": "pnpm --filter @faunosteo/app preview", "build": "pnpm -r build", "typecheck": "pnpm -r typecheck", @@ -23,12 +23,13 @@ "check:all": "bash scripts/check-all.sh", "report:compare": "pnpm --filter @faunosteo/app report:compare", "import:equine": "pnpm --filter @faunosteo/anatomy import:equine", - "db:start": "supabase start", - "db:stop": "supabase stop", - "db:reset": "supabase db reset", - "db:test": "supabase test db", - "db:types": "supabase gen types typescript --local --schema public | prettier --parser typescript > packages/supabase/src/database.types.ts", - "db:types:check": "supabase gen types typescript --local --schema public | prettier --parser typescript | diff - packages/supabase/src/database.types.ts", + "supabase": "bash scripts/supabase.sh", + "db:start": "bash scripts/supabase.sh start", + "db:stop": "bash scripts/supabase.sh stop", + "db:reset": "bash scripts/supabase.sh db reset", + "db:test": "bash scripts/supabase.sh test db", + "db:types": "bash scripts/supabase.sh gen types typescript --local --schema public | prettier --parser typescript > packages/supabase/src/database.types.ts", + "db:types:check": "bash scripts/supabase.sh gen types typescript --local --schema public | prettier --parser typescript | diff - packages/supabase/src/database.types.ts", "assets:upload": "pnpm --filter @faunosteo/supabase assets:upload", "build:preview": "SHEET_BUNDLE=draft pnpm --filter @faunosteo/app build", "preview:draft": "SHEET_BUNDLE=draft pnpm --filter @faunosteo/app build && pnpm --filter @faunosteo/app preview", diff --git a/scripts/avatar-e2e.sh b/scripts/avatar-e2e.sh index f981546d..0a1a3b9d 100755 --- a/scripts/avatar-e2e.sh +++ b/scripts/avatar-e2e.sh @@ -14,6 +14,7 @@ kong="${SUPABASE_INTERNAL_URL:-http://supabase_kong_faunosteo:8000}" image="${WORKER_IMAGE:-faunosteo_worker:dev}" name="faunosteo_worker_e2e" +. scripts/dev-env.sh status="$(node_modules/.bin/supabase status -o env 2>/dev/null)" \ || { echo "avatar-e2e: the local stack is not running (pnpm db:start)" >&2; exit 1; } value() { printf '%s\n' "$status" | sed -n "s/^$1=\"\(.*\)\"$/\1/p"; } diff --git a/scripts/dev-env.sh b/scripts/dev-env.sh new file mode 100644 index 00000000..5bc0a3e9 --- /dev/null +++ b/scripts/dev-env.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +# shellcheck shell=bash +# The one place the DEV origin is decided (docs/development/ENVIRONMENTS.md §2). +# Sourced by the wrappers (scripts/supabase.sh, scripts/dev.sh, scripts/avatar-e2e.sh): +# every service the browser of another device must reach is addressed by the +# host's LAN address, never by 127.0.0.1 or localhost. +# +# FAUNOSTEO_DEV_HOST the address or name of this machine on the private network; +# unset = the first non-loopback IPv4 of the host; 127.0.0.1 for +# a host-only session. Never a production host. +# +# Exports FAUNOSTEO_DEV_HOST and the derived URLs read by supabase/config.toml +# (env() substitution) and by the Vite dev server. +if [ -z "${FAUNOSTEO_DEV_HOST:-}" ]; then + FAUNOSTEO_DEV_HOST="$(hostname -I 2>/dev/null | awk '{print $1}')" + [ -n "$FAUNOSTEO_DEV_HOST" ] || FAUNOSTEO_DEV_HOST=127.0.0.1 +fi +case "$FAUNOSTEO_DEV_HOST" in + *faunosteo.com*) echo "dev-env: FAUNOSTEO_DEV_HOST must never be a production host ($FAUNOSTEO_DEV_HOST)" >&2; return 1 ;; +esac +export FAUNOSTEO_DEV_HOST +export FAUNOSTEO_DEV_API_ORIGIN="http://$FAUNOSTEO_DEV_HOST" +export FAUNOSTEO_DEV_API_URL="http://$FAUNOSTEO_DEV_HOST:54321" +export FAUNOSTEO_DEV_SITE_URL="http://$FAUNOSTEO_DEV_HOST:5173" +export FAUNOSTEO_DEV_STUDIO_URL="http://$FAUNOSTEO_DEV_HOST:54323" +export FAUNOSTEO_DEV_MAILPIT_URL="http://$FAUNOSTEO_DEV_HOST:54324" diff --git a/scripts/dev-lan.sh b/scripts/dev-lan.sh deleted file mode 100755 index b1cb99cc..00000000 --- a/scripts/dev-lan.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash -# Vite dev server reachable from the LAN, wired to the local Supabase stack by the -# host's LAN address (the stack publishes 54321 / 54323 / 54324 on every interface). -# Usage: pnpm dev:lan [host-ip] (default: the first non-loopback IPv4 of this host) -set -euo pipefail -cd "$(dirname "$0")/.." -ip="${1:-$(hostname -I 2>/dev/null | awk '{print $1}')}" -[ -n "$ip" ] || { echo "dev-lan: pass the host IP as the first argument" >&2; exit 1; } -anon="$(node_modules/.bin/supabase status -o env 2>/dev/null | sed -n 's/^ANON_KEY="\(.*\)"$/\1/p')" -[ -n "$anon" ] || { echo "dev-lan: local stack not running (pnpm db:start)" >&2; exit 1; } -echo "== app http://$ip:5173 supabase http://$ip:54321 studio http://$ip:54323 mailpit http://$ip:54324" -VITE_SUPABASE_URL="http://$ip:54321" VITE_SUPABASE_ANON_KEY="$anon" \ - exec node_modules/.bin/pnpm --filter @faunosteo/app exec vite --host 0.0.0.0 --port 5173 diff --git a/scripts/dev.sh b/scripts/dev.sh new file mode 100755 index 00000000..d15b9e7e --- /dev/null +++ b/scripts/dev.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +# Vite dev server reachable from the private network, wired to the local +# Supabase stack by the DEV origin (scripts/dev-env.sh). Vite listens on every +# interface (apps/app/vite.config.ts server.host); HMR follows the page host. +# pnpm dev # http://:5173 +# pnpm dev:offline # no backend: the local tool alone +set -euo pipefail +cd "$(dirname "$0")/.." +. scripts/dev-env.sh +anon="$(node_modules/.bin/supabase status -o env 2>/dev/null | sed -n 's/^ANON_KEY="\(.*\)"$/\1/p')" +[ -n "$anon" ] || { echo "dev: the local stack is not running (pnpm db:start), or use pnpm dev:offline" >&2; exit 1; } +echo "== app $FAUNOSTEO_DEV_SITE_URL api $FAUNOSTEO_DEV_API_URL studio $FAUNOSTEO_DEV_STUDIO_URL mailpit $FAUNOSTEO_DEV_MAILPIT_URL" +VITE_SUPABASE_URL="$FAUNOSTEO_DEV_API_URL" VITE_SUPABASE_ANON_KEY="$anon" \ + exec node_modules/.bin/pnpm --filter @faunosteo/app exec vite --port 5173 --strictPort diff --git a/scripts/supabase.sh b/scripts/supabase.sh new file mode 100755 index 00000000..6d73e73c --- /dev/null +++ b/scripts/supabase.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +# Supabase CLI with the DEV origin exported: supabase/config.toml reads the +# API external URL, the site URL and Studio's API URL through env(), so every +# CLI call (start, stop, status, db reset, test db, gen types) must see them, +# or the literal "env(...)" text lands in the running services. +# pnpm supabase · pnpm db:start · FAUNOSTEO_DEV_HOST=10.0.0.5 pnpm db:start +set -euo pipefail +cd "$(dirname "$0")/.." +. scripts/dev-env.sh +exec node_modules/.bin/supabase "$@" diff --git a/supabase/config.toml b/supabase/config.toml index 52c33fab..018680c2 100644 --- a/supabase/config.toml +++ b/supabase/config.toml @@ -6,9 +6,11 @@ project_id = "faunosteo" [api] enabled = true port = 54321 -# LAN development: the address written into confirmation and recovery mails -# (GoTrue API_EXTERNAL_URL). Keep 127.0.0.1 when working on the host alone. -external_url = "http://192.168.1.100:54321" +# DEV origin (scripts/dev-env.sh, exported by every CLI call through scripts/supabase.sh): +# the address written into confirmation and recovery mails (GoTrue API_EXTERNAL_URL). +# Tests run from other devices of the private network, so it is the host's LAN +# address, never 127.0.0.1 (docs/development/ENVIRONMENTS.md). +external_url = "env(FAUNOSTEO_DEV_API_URL)" # Only public is exposed through PostgREST. private and audit stay internal # (docs/development/BACKEND_ARCHITECTURE.md §3). schemas = ["public"] @@ -48,7 +50,8 @@ enabled = false [studio] enabled = true port = 54323 -api_url = "http://127.0.0.1" +# Origin the remote browser running Studio calls the API on (same DEV origin, no port). +api_url = "env(FAUNOSTEO_DEV_API_ORIGIN)" # Local mail catcher: confirmation and OTP mails land at http://127.0.0.1:54324 [local_smtp] @@ -70,10 +73,10 @@ enabled = false [auth] enabled = true -# Vite dev server of apps/app -site_url = "http://192.168.1.100:5173" -# LAN access (pnpm dev:lan): confirmation and recovery links must land on the -# address the browser used, so every private-network host on :5173 is allowed. +# Vite dev server of apps/app on the DEV origin (scripts/dev-env.sh) +site_url = "env(FAUNOSTEO_DEV_SITE_URL)" +# Confirmation and recovery links land on the address the browser used: every +# private-network host on :5173 is allowed, plus the host-only forms. additional_redirect_urls = [ "http://127.0.0.1:5173", "http://localhost:5173",