diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..1ea0527 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,59 @@ +# AGENTS.md — OweMe + +End-to-end encrypted group expense splitter (a Settle Up clone). Read +`SPEC.md` first; it is the source of truth for behaviour and is kept current. + +## Layout +- `packages/core/` — pure TypeScript shared by client and service worker: + event schema, validation, money math, replay/rewind, settle-up, recurring, + stats, CSV. **No I/O, no floats for money.** +- `apps/server/` — Node 24, **standard library only** (`node:http`, + `node:sqlite`, `node:crypto`), run directly as TypeScript (type stripping: + erasable syntax only, `.ts` import extensions). No npm dependencies; keep it + that way unless there's a strong reason. +- `apps/web/` — Svelte 5 SPA + service worker (`src/sw.ts`, built separately + by `vite.sw.config.ts` as a classic script). +- `deploy/` — Containerfile, compose.yaml, Caddyfile, `.env.example`, deploy docs. +- `e2e/` — Playwright tests against the production build. + +## Run +Node lives at `~/.local/node/bin` on the dev box (not on PATH by default). + +```sh +npm ci +npm run dev # API 127.0.0.1:8481 + Vite 127.0.0.1:8480 +``` +Preview from your machine: `ssh -p 14922 -L 8480:localhost:8480 `, +then http://localhost:8480. + +## Test +```sh +npm test # core (vitest) + server (node:test) +npm run check # tsc + svelte-check (must be 0 errors, 0 warnings) +npm run build && npm run test:e2e +``` +E2E uses the Playwright browsers cached in `~/.cache/ms-playwright` +(`@playwright/test` is pinned to 1.63.0 to match them). `e2e/push.spec.ts` +needs full Chromium (`channel: 'chromium'`): the headless shell denies +notifications. + +## Invariants — do not break +1. **The server never sees plaintext or keys.** The group secret exists only + in the URL fragment, IndexedDB and backup files. Never send it in a path, + query string, header or log line. The server stores `SHA-256(authToken)`. +2. **Every client computes identical balances.** Money is integer minor units; + rates are decimal strings; rounding is largest-remainder with ties to + member order, conversion is round-half-even (BigInt). Any change to money + math needs a test in `packages/core/test/`. +3. **The event log is append-only.** Undo is a new event (`revert`, + `expense.restored`, …), never a deletion. Replay must ignore invalid + events (`validateExpense`), not crash. +4. **New event types** go in `types.ts` (`EventBody`), `replay.ts` (with + validation), the activity text in `Activity.svelte` and both locale files. +5. **i18n:** every string in `locales/en.ts` and `locales/cs.ts` (the type + enforces it). English is the default; Czech only if the browser prefers it. +6. **Push endpoints** are restricted to the allowlist in `push.ts` (no SSRF). + Push payloads carry only the group id. +7. Strict CSP: no inline scripts, no third-party origins. +8. Containers: rootless Podman; for local testing publish to `127.0.0.1` only + (`BIND_ADDR=127.0.0.1` in `deploy/.env`). diff --git a/README.md b/README.md index b27f8da..b0038dd 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,24 @@ # OweMe -End-to-end encrypted, mobile-first group expense splitter. See [SPEC.md](SPEC.md). +Split group expenses with friends: a mobile-first, **end-to-end encrypted** +Settle Up clone that runs in any browser and installs as an app. + +- Groups you open via a link; the key travels in the `#fragment` and never reaches the server +- Equal, shares, exact-amount and percent splits; several payers; any member can be left out +- Multiple currencies with ECB daily rates (stored per expense, editable) +- One receipt photo per expense (resized, location data stripped, encrypted) +- Who-pays-whom settle-up suggestions, with "record payment" +- Full history: restore any version, or rewind the whole group (and undo that) +- Comments, categories, statistics, recurring expenses, CSV export, backup files +- Push notifications that the server can't read +- Works offline; English and Czech; dark and light money-green theme + +See [SPEC.md](SPEC.md) for the design, [deploy/README.md](deploy/README.md) +to run it on a VPS with `podman compose`, and [AGENTS.md](AGENTS.md) for +development. + +```sh +npm ci +npm run dev # http://127.0.0.1:8480 +npm test +``` diff --git a/SPEC.md b/SPEC.md index 2130f2f..4ba86e8 100644 --- a/SPEC.md +++ b/SPEC.md @@ -3,7 +3,7 @@ A mobile-first, end-to-end encrypted group expense splitter (a Settle Up clone) that runs in any browser, on phones and desktops alike. -Status: **v1, agreed** · Last updated: 2026-10-09 +Status: **v1, implemented** · Last updated: 2026-10-09 --- @@ -138,7 +138,7 @@ Decrypted plaintext: | `expense.deleted` / `expense.restored` | expenseId | | `comment.added` / `comment.deleted` | commentId, expenseId, text | | `recurring.created` / `recurring.updated` / `recurring.deleted` | template (see 7.4) | -| `revert` | targetSeq — see 6.2 | +| `revert` | targetId (an event id) — see 6.2 | Updates carry the full new object (not a diff), so the latest event per entity fully defines it. Conflicts resolve **last-writer-wins by server @@ -244,10 +244,12 @@ the minimum in practice, and is easy to reason about. - **Restore an expense**: undelete, or roll it back to a chosen earlier version (emits `expense.updated` / `expense.restored` with the old content). -- **Rewind the whole group to a point in time**: emits a `revert { targetSeq }` - event. Replay treats the state as the state at `targetSeq`, and then applies - later events normally. Nothing is ever erased, so a rewind can itself be - undone (revert to the seq just before the revert). +- **Rewind the whole group to a point in time**: emits a `revert { targetId }` + event naming an earlier event. Replay replaces the state with a snapshot + taken right after that event, then applies later events normally. Nothing + is ever erased, so a rewind can itself be undone (revert to the event just + before the revert). Event ids rather than seqs are used so a restored + backup, which gets new seqs, keeps working. - The log is append-only on the server; there is no destructive delete API for events (only deleting the entire group, see 8.3). @@ -293,8 +295,9 @@ Transfers have their own implicit category. - There is no server-side worker (the server cannot read templates). When any member's client opens the group and a due occurrence is missing, it creates it. The occurrence's expense ID is derived deterministically - (`UUIDv5(templateId + occurrenceDate)`), so two clients doing it at once - produce the same ID and replay deduplicates it. + (`rec--`), so two clients doing it at once + produce the same ID; `expense.created` is first-wins on replay, so the + duplicate is ignored. Deleted occurrences are not recreated. - Occurrences are normal expenses (editable/deletable individually). ### 7.5 Statistics @@ -310,17 +313,27 @@ Client-side charts per group, filterable by date range: - **CSV export** of expenses (one row per expense, columns per member share) and of current balances. -- **Encrypted backup**: full event log + photos as one file, encrypted with - the group key. Restoring it recreates the group on the same or a new server. +- **Backup file** (JSON): the encrypted event log and photos exactly as the + server stores them, **plus the group secret**, so a group can be restored + even if every link is lost. The file is therefore as sensitive as the link, + and the UI says so. Restoring creates the group on the server (or finds it + already there) and re-uploads everything; uploads are idempotent by id, so + an interrupted restore can simply be run again. ### 7.7 Push notifications - Opt-in per group per device (Web Push, VAPID). - Because the server cannot read events, the push it sends **contains no - content**, just `{ groupId }`. The service worker wakes, fetches new events, - decrypts them locally and shows "Anna added Dinner · 120.50 EUR". + content**, just `{ g: groupId }` (itself encrypted to the browser per + RFC 8291). The service worker wakes, fetches new events, decrypts them + locally and shows "Anna: Dinner · 120.50 EUR". It stays quiet if that + group is open and focused. - The server skips the device that created the event (`deviceId`). -- Notification options: all activity / only expenses involving me. +- On/off per group only. An "only expenses involving me" option was dropped: + browsers require every push to show a notification, so the worker can't + silently discard irrelevant ones. +- The server only delivers to known push services (FCM, Mozilla, Apple, + Windows), so a registered endpoint can't make it call arbitrary hosts. - iOS: works only when the app is installed to the home screen (iOS 16.4+); the UI explains this. @@ -345,13 +358,18 @@ All group endpoints require `Authorization: Bearer `. | `POST/DELETE /api/groups/:id/push` | Register/unregister a Web Push subscription. | | `DELETE /api/groups/:id` | Delete group, events and blobs (requires typing the group name client-side as confirmation). | | `GET /api/rates?date=YYYY-MM-DD` | Daily reference rates (no auth). | +| `GET /api/config` | Public settings: VAPID public key, size limits (no auth). | | `GET /api/health` | Health check. | +Unknown groups and wrong tokens both answer `404`, so the API doesn't reveal +which group ids exist. + ### 8.2 Exchange rates -- The server fetches **ECB daily reference rates** (~30 currencies, via - Frankfurter or ECB XML directly) once a day and caches them in SQLite, - including history for back-dated expenses. +- The server fetches **ECB daily reference rates** (~30 currencies, from the + ECB's own XML feed) every 6 hours and caches them in SQLite. The first run + loads the full history (back to 1999) for back-dated expenses; later runs + fetch the last 90 days. - Clients fetch from our server only, so third parties don't learn users' IPs or currency usage. Clients cache rates offline. - Currencies outside the ECB set can be used with a manually entered rate. @@ -364,7 +382,8 @@ All group endpoints require `Authorization: Bearer `. - Limits (env variables, see 13): photo blob ≤ 2 MB (`MAX_PHOTO_BYTES`), event ≤ 64 KB (`MAX_EVENT_BYTES`), per-group storage ≤ 200 MB (`MAX_GROUP_BYTES`), group creation rate limit (`GROUP_CREATE_PER_HOUR`). - The thumbnail counts as part of its photo. + The server enforces the photo limit per uploaded blob; the client keeps a + photo and its thumbnail together under it. - Inactive-group retention: none by default (configurable). --- @@ -461,23 +480,24 @@ Hardening: | Layer | Choice | Why | |---|---|---| -| Frontend | **SvelteKit** (static adapter, SPA) + TypeScript | Small bundles (fast on phones), simple reactivity | -| PWA | Vite PWA plugin (Workbox) | Service worker, offline cache, push handling | -| Local storage | IndexedDB (via `idb`) | Groups, events, blobs cache | -| Charts | Lightweight library (e.g. Chart.js or LayerCake) | Stats tab | -| i18n | `svelte-i18n` or a small typed dictionary | EN/CS | -| Backend | **Bun + Hono** + TypeScript | Tiny, fast, shares types with the frontend | -| DB | SQLite (`bun:sqlite`) | Zero-ops, single file | +| Frontend | **Svelte 5 + Vite** SPA, TypeScript, a ~60-line history router | Small bundle (~65 KB gzipped), simple reactivity; SvelteKit wasn't needed for a static SPA | +| PWA | Hand-written service worker, built as a classic script by a second Vite step | Offline shell, push handling; no Workbox dependency | +| Local storage | IndexedDB (small hand-written wrapper) | Groups, events, outbox, blobs cache; shared with the service worker | +| Charts | Hand-built HTML/CSS bars | Stats tab; no chart library | +| i18n | Small typed dictionary (`locales/en.ts`, `cs.ts`) | EN/CS; the type makes missing translations a compile error | +| Backend | **Node 24, standard library only** (`node:http`, `node:sqlite`, `node:crypto`), run as TypeScript via type stripping | No npm dependencies on the server; Node was already on the dev box (Bun would have meant another runtime) | +| DB | SQLite (`node:sqlite`) | Zero-ops, single file | | Tests | Vitest (money math, replay, crypto), Playwright (E2E on mobile + desktop viewports) | Rounding and replay must be bulletproof | | Proxy/TLS | **Caddy** | Automatic HTTPS (required for WebCrypto, service workers and push) | Repo layout (monorepo): ``` -apps/web SvelteKit client -apps/server Bun + Hono API -packages/core shared: types, event schema, money math, replay, crypto -deploy/ compose.yaml, Caddyfile, .env.example +apps/web Svelte client + service worker +apps/server Node API (no dependencies) +packages/core shared: types, event schema, money math, replay, settle-up, recurring, stats, CSV +deploy/ Containerfile, compose.yaml, Caddyfile, .env.example, README +e2e/ Playwright tests ``` --- @@ -486,7 +506,7 @@ deploy/ compose.yaml, Caddyfile, .env.example `deploy/compose.yaml` runs two services: -- `app`: the Bun server, which also serves the built static client. Listens +- `app`: the Node server, which also serves the built static client. Listens on the internal network only. - `caddy`: TLS termination + reverse proxy, the only service publishing ports (80/443). @@ -497,15 +517,15 @@ Deploy steps (documented in `deploy/README.md`): 1. Point a DNS A/AAAA record at the VPS. 2. `cp deploy/.env.example deploy/.env && chmod 600 deploy/.env`, then set - `DOMAIN` (e.g. `oweme.example.com`). `compose.yaml` passes it to both - services as `${DOMAIN}`: Caddy uses it for the site address and - certificate, and the app uses it for share links and the CSP. Generate - VAPID keys with the provided script, which writes them into `.env` without - printing them. + `DOMAIN` (e.g. `oweme.example.com`); Caddy uses it for the site address + and certificate. (The app itself needs no domain: share links use the + page's own origin and the CSP is `'self'`.) Generate VAPID keys with + `gen-vapid.ts` inside the built image, which writes them into `.env` + without printing them. 3. Rootless Podman cannot bind ports < 1024 by default: either set `net.ipv4.ip_unprivileged_port_start=80` via sysctl, or publish 8080/8443 and redirect with the firewall — both documented. -4. `podman compose up -d`. Updates: `git pull && podman compose up -d --build`. +4. `cd deploy && podman compose up -d`. Updates: `git pull && podman compose up -d --build`. 5. Backups: copy the data volume. All contents are already encrypted, so backups can be stored anywhere. @@ -514,12 +534,14 @@ Environment variables (`deploy/.env`, read by `compose.yaml`): | Variable | Required | Default | Purpose | |---|---|---|---| | `DOMAIN` | yes | — | Public hostname; Caddy site + TLS, share links | -| `VAPID_PUBLIC_KEY` / `VAPID_PRIVATE_KEY` | yes | — | Web Push (generated by script) | -| `VAPID_SUBJECT` | yes | — | `mailto:` contact for push services | +| `VAPID_PUBLIC_KEY` / `VAPID_PRIVATE_KEY` | for push | — | Web Push (generated by script); empty = notifications off | +| `VAPID_SUBJECT` | for push | — | `mailto:` contact for push services | | `MAX_PHOTO_BYTES` | no | `2097152` | Per-photo upload cap | | `MAX_EVENT_BYTES` | no | `65536` | Per-event cap | | `MAX_GROUP_BYTES` | no | `209715200` | Per-group storage cap | | `GROUP_CREATE_PER_HOUR` | no | `10` | Group creations per IP per hour | +| `BIND_ADDR` | no | `0.0.0.0` | Address Caddy's ports are published on | +| `HTTP_PORT` / `HTTPS_PORT` | no | `80` / `443` | Host ports for Caddy | Development (on the dev box): servers bind `127.0.0.1` only; preview over an SSH tunnel. Ports and commands go in `AGENTS.md`. @@ -528,12 +550,14 @@ SSH tunnel. Ports and commands go in `AGENTS.md`. ## 14. Milestones +All five milestones below shipped together in the first implementation +(2026-10-09): + 1. **Core**: crypto, event log, sync, groups (link + QR), members, identity, - expenses with all split modes in a single currency, balances, settle-up, - transfers, remembered groups, EN/CS, dark/light theme, PWA + offline, - podman compose deploy. + expenses with all split modes, balances, settle-up, transfers, remembered + groups, EN/CS, dark/light theme, PWA + offline, podman compose deploy. 2. **Money & media**: multiple currencies + rates service, photos. 3. **History**: activity feed, per-expense history, restore, group rewind. 4. **Extras**: comments, categories, statistics, recurring expenses, CSV - export, encrypted backup/restore. + export, backup/restore. 5. **Notifications**: Web Push. diff --git a/deploy/.env.example b/deploy/.env.example new file mode 100644 index 0000000..d40ace4 --- /dev/null +++ b/deploy/.env.example @@ -0,0 +1,23 @@ +# Copy to deploy/.env and `chmod 600 deploy/.env`. Never commit .env. + +# Required: public hostname, with a DNS A/AAAA record pointing at this server. +DOMAIN=oweme.example.com + +# Web Push. Generate the keys with: +# podman run --rm --user root -v ./:/out:Z localhost/oweme:latest node server/gen-vapid.ts /out/.env +# (or, with Node 24 installed: node apps/server/src/gen-vapid.ts deploy/.env) +# Leave empty to disable notifications. +VAPID_SUBJECT=mailto:you@example.com +VAPID_PUBLIC_KEY= +VAPID_PRIVATE_KEY= + +# Limits (bytes). Defaults shown. +MAX_PHOTO_BYTES=2097152 +MAX_EVENT_BYTES=65536 +MAX_GROUP_BYTES=209715200 +GROUP_CREATE_PER_HOUR=10 + +# Where Caddy listens. Defaults: all interfaces, ports 80/443. +#BIND_ADDR=0.0.0.0 +#HTTP_PORT=80 +#HTTPS_PORT=443 diff --git a/deploy/Caddyfile b/deploy/Caddyfile new file mode 100644 index 0000000..171291f --- /dev/null +++ b/deploy/Caddyfile @@ -0,0 +1,10 @@ +# Automatic HTTPS for $DOMAIN (Let's Encrypt / ZeroSSL). HTTPS is required: +# WebCrypto, service workers and push only work in a secure context. +# Security headers (CSP etc.) are set by the app itself. +{$DOMAIN} { + encode zstd gzip + reverse_proxy app:8080 { + # Server-Sent Events: don't buffer + flush_interval -1 + } +} diff --git a/deploy/Containerfile b/deploy/Containerfile new file mode 100644 index 0000000..f5d4127 --- /dev/null +++ b/deploy/Containerfile @@ -0,0 +1,29 @@ +# OweMe: one image with the server (Node standard library only, no +# node_modules) and the built web client. Build context: the repo root. + +FROM docker.io/library/node:24.21.0-alpine AS build +WORKDIR /src +COPY package.json package-lock.json ./ +COPY packages/core/package.json packages/core/ +COPY apps/web/package.json apps/web/ +# --ignore-scripts: no install hooks from dependencies run during the build. +RUN npm ci --no-audit --no-fund --ignore-scripts +COPY packages/core packages/core +COPY apps/web apps/web +RUN npm run build -w apps/web + +FROM docker.io/library/node:24.21.0-alpine +WORKDIR /app +ENV NODE_ENV=production \ + HOST=0.0.0.0 \ + PORT=8080 \ + DATA_DIR=/data \ + STATIC_DIR=/app/web \ + TRUST_PROXY=1 +COPY apps/server/src ./server +COPY --from=build /src/apps/web/dist ./web +RUN mkdir -p /data && chown node:node /data +USER node +VOLUME /data +EXPOSE 8080 +CMD ["node", "--disable-warning=ExperimentalWarning", "server/main.ts"] diff --git a/deploy/README.md b/deploy/README.md new file mode 100644 index 0000000..d07d670 --- /dev/null +++ b/deploy/README.md @@ -0,0 +1,92 @@ +# Deploying OweMe on a VPS + +Two containers via `podman compose`: **app** (the Node server plus the built +web client) and **caddy** (HTTPS and reverse proxy). Only Caddy publishes ports. + +## Requirements + +- Podman ≥ 4 with `podman compose` (podman-compose or docker-compose as the provider) +- A domain with an A/AAAA record pointing at the VPS +- Ports 80 and 443 (TCP, plus UDP 443 for HTTP/3) open in the firewall + +## First deploy + +```sh +git clone oweme && cd oweme/deploy + +cp .env.example .env +chmod 600 .env +$EDITOR .env # set DOMAIN and VAPID_SUBJECT (mailto:) + +podman compose build # builds localhost/oweme:latest +# Web Push keys: written into .env, private key never printed. +podman run --rm --user root -v ./:/out:Z localhost/oweme:latest node server/gen-vapid.ts /out/.env + +podman compose up -d +podman compose logs -f # Caddy obtains the certificate on first request +``` + +Open `https://$DOMAIN`. `curl https://$DOMAIN/api/health` should say `{"ok":true}`. + +## Updating + +```sh +cd oweme && git pull +cd deploy && podman compose up -d --build +``` + +Data lives in the `oweme-data` volume and survives rebuilds. + +## Configuration (`deploy/.env`) + +| Variable | Required | Default | Purpose | +|---|---|---|---| +| `DOMAIN` | yes | — | Public hostname; Caddy's site address and certificate | +| `VAPID_SUBJECT` | for push | — | `mailto:` contact sent to push services | +| `VAPID_PUBLIC_KEY` / `VAPID_PRIVATE_KEY` | for push | — | Generated by `gen-vapid.ts`; empty = notifications off | +| `MAX_PHOTO_BYTES` | no | `2097152` | Max size of one uploaded (encrypted) photo | +| `MAX_EVENT_BYTES` | no | `65536` | Max size of one encrypted event | +| `MAX_GROUP_BYTES` | no | `209715200` | Storage cap per group (events + photos) | +| `GROUP_CREATE_PER_HOUR` | no | `10` | Group creations per client IP per hour | +| `BIND_ADDR` | no | `0.0.0.0` | Address Caddy's ports are published on | +| `HTTP_PORT` / `HTTPS_PORT` | no | `80` / `443` | Host ports for Caddy | + +Rotating the VAPID keys (`gen-vapid.ts … --force`) silently invalidates every +push subscription; users have to toggle notifications off and on again. + +## Ports (rootless Podman) + +Rootless Podman can't bind ports below 1024 by default. Pick one: + +1. Allow it (simplest): + ```sh + echo 'net.ipv4.ip_unprivileged_port_start=80' | sudo tee /etc/sysctl.d/90-unprivileged-ports.conf + sudo sysctl --system + ``` +2. Or publish high ports (`HTTP_PORT=8080`, `HTTPS_PORT=8443`) and redirect + 80→8080 / 443→8443 in your firewall (e.g. nftables/UFW `nat` rules). + +With rootless Podman, published ports go through `rootlessport` and are +subject to the host firewall. Rootful container networking can add its own +firewall rules around UFW, so don't rely on UFW alone if you run rootful. + +## Backups + +Back up the `oweme-data` volume (SQLite database + encrypted photos): + +```sh +podman volume export oweme_oweme-data > oweme-data-$(date +%F).tar +``` + +Everything in it is already end-to-end encrypted, so the backup can be stored +anywhere. Users can also download per-group backup files in the app. + +## Testing a deployment + +From a machine with the repo and Node 24: + +```sh +npm ci && E2E_BASE_URL=https://$DOMAIN npx playwright test e2e/app.spec.ts +``` + +This creates a throwaway group on that server. diff --git a/deploy/compose.yaml b/deploy/compose.yaml new file mode 100644 index 0000000..c5ccc90 --- /dev/null +++ b/deploy/compose.yaml @@ -0,0 +1,49 @@ +# podman compose up -d --build (run from this directory; reads ./.env) +# See deploy/README.md for the full deploy steps. +name: oweme + +services: + app: + build: + context: .. + dockerfile: deploy/Containerfile + image: localhost/oweme:latest + restart: unless-stopped + env_file: .env + environment: + # fixed inside the container; everything else comes from .env + HOST: 0.0.0.0 + PORT: "8080" + DATA_DIR: /data + STATIC_DIR: /app/web + TRUST_PROXY: "1" + volumes: + - oweme-data:/data + healthcheck: + test: ["CMD", "wget", "-qO-", "http://127.0.0.1:8080/api/health"] + interval: 30s + timeout: 5s + # no published ports: only Caddy can reach the app + + caddy: + image: docker.io/library/caddy:2.10.2-alpine + restart: unless-stopped + depends_on: + - app + environment: + DOMAIN: ${DOMAIN:?set DOMAIN in deploy/.env} + ports: + # BIND_ADDR defaults to all interfaces (a public VPS). Rootless Podman + # can't bind ports below 1024 by default; see README "Ports". + - "${BIND_ADDR:-0.0.0.0}:${HTTP_PORT:-80}:80" + - "${BIND_ADDR:-0.0.0.0}:${HTTPS_PORT:-443}:443" + - "${BIND_ADDR:-0.0.0.0}:${HTTPS_PORT:-443}:443/udp" + volumes: + - ./Caddyfile:/etc/caddy/Caddyfile:ro,Z + - caddy-data:/data + - caddy-config:/config + +volumes: + oweme-data: + caddy-data: + caddy-config: diff --git a/scripts/dev.mjs b/scripts/dev.mjs new file mode 100644 index 0000000..5ea283a --- /dev/null +++ b/scripts/dev.mjs @@ -0,0 +1,16 @@ +// `npm run dev`: API server on 127.0.0.1:8481 (restarts on change) and the +// Vite dev server on 127.0.0.1:8480 (proxies /api). Data goes to ./data. +import { spawn } from 'node:child_process'; + +const procs = [ + spawn(process.execPath, ['--watch', '--disable-warning=ExperimentalWarning', 'apps/server/src/main.ts'], { + stdio: 'inherit', + env: { ...process.env, PORT: '8481', DATA_DIR: process.env.DATA_DIR ?? 'data' }, + }), + spawn('npm', ['run', 'dev', '-w', 'apps/web'], { stdio: 'inherit' }), +]; + +const stop = () => procs.forEach((p) => p.kill('SIGTERM')); +process.on('SIGINT', stop); +process.on('SIGTERM', stop); +for (const p of procs) p.on('exit', (code) => { stop(); process.exitCode = code ?? 0; });