diff --git a/.env.example b/.env.example index 406b44d..f7dbe24 100644 --- a/.env.example +++ b/.env.example @@ -10,7 +10,7 @@ PORT=3003 # Directory for the SQLite FCM registration database (default: ./data). # Creates notify.sqlite (plus -wal/-shm while the process is running). -# FCM_TOKEN_DATA_DIR=./data +# NOTIFY_DATA_DIR=./data # Set to "test-local" to bypass ethr JWT expiry verification in local dev only. # NODE_ENV=test-local diff --git a/README.md b/README.md index 7ee2d38..39df998 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Here is one way to generate the contents: `cat your-downloaded-key.json | jq -c Optionally set `ENDORSER_URL` if you are not using the default production Endorser API (`https://api.endorser.ch`). -Optionally set `FCM_TOKEN_DATA_DIR` if you want the SQLite database somewhere other than `./data`. +Optionally set `NOTIFY_DATA_DIR` if you want the SQLite database somewhere other than `./data`. ```bash pnpm install @@ -22,7 +22,7 @@ pnpm run dev The server starts on `http://localhost:3003` (or the port in `PORT`). Hot-reloads on file changes. -On first use, the service creates `FCM_TOKEN_DATA_DIR` (default `./data`) and the SQLite file `notify.sqlite` with the required schema. +On first use, the service creates `NOTIFY_DATA_DIR` (default `./data`) and the SQLite file `notify.sqlite` with the required schema. ### Authentication @@ -38,11 +38,11 @@ Set `NODE_ENV=test-local` in `.env` to bypass ethr JWT *expiry* verification dur | Path | Description | |---|---| -| `{FCM_TOKEN_DATA_DIR}/notify.sqlite` | Primary SQLite database (default dir: `./data`) | -| `{FCM_TOKEN_DATA_DIR}/notify.sqlite-wal` | WAL journal (present while the process is running) | -| `{FCM_TOKEN_DATA_DIR}/notify.sqlite-shm` | Shared-memory file used with WAL mode | +| `{NOTIFY_DATA_DIR}/notify.sqlite` | Primary SQLite database (default dir: `./data`) | +| `{NOTIFY_DATA_DIR}/notify.sqlite-wal` | WAL journal (present while the process is running) | +| `{NOTIFY_DATA_DIR}/notify.sqlite-shm` | Shared-memory file used with WAL mode | -`FCM_TOKEN_DATA_DIR` defaults to `./data` (relative to the process working directory). The `data/` directory is gitignored. +`NOTIFY_DATA_DIR` defaults to `./data` (relative to the process working directory). The `data/` directory is gitignored. ### Schema (high level) @@ -62,11 +62,11 @@ There is **no automatic migration** from the old JSON file (`fcm-tokens.json`). ### Backup -Persist or back up the SQLite files under `FCM_TOKEN_DATA_DIR`: +Persist or back up the SQLite files under `NOTIFY_DATA_DIR`: 1. Prefer stopping the service, then copy `notify.sqlite` (and any `-wal` / `-shm` sidecars if present). 2. Or, while the service is running, copy **all three** files (`notify.sqlite`, `-wal`, `-shm`) together so the backup stays consistent under WAL mode. -3. For Docker, mount a volume at the data directory (or set `FCM_TOKEN_DATA_DIR` to a mounted path) so registrations survive container recreation. +3. For Docker, mount a volume at the data directory (or set `NOTIFY_DATA_DIR` to a mounted path) so registrations survive container recreation. ## Production @@ -77,7 +77,7 @@ pnpm install --prod pnpm start ``` -Ensure `FCM_TOKEN_DATA_DIR` points at a durable location (or accept the default `./data` next to the process cwd). +Ensure `NOTIFY_DATA_DIR` points at a durable location (or accept the default `./data` next to the process cwd). Or with Docker: @@ -88,7 +88,7 @@ docker run --env-file notify-wakeup-api.env -p 3003:3003 \ notify-wakeup-api ``` -Mount a volume over `/app/data` (or whatever path you set with `FCM_TOKEN_DATA_DIR`) so the SQLite database is not lost when the container is replaced. +Mount a volume over `/app/data` (or whatever path you set with `NOTIFY_DATA_DIR`) so the SQLite database is not lost when the container is replaced. Required environment variables: @@ -97,4 +97,4 @@ Required environment variables: | `FIREBASE_SERVICE_ACCOUNT_JSON` | Inline service account JSON (one line). If unset, falls back to Application Default Credentials. | | `PORT` | HTTP port (default: `3003`). | | `ENDORSER_URL` | Endorser API base URL used for auth checks on register/refresh (default: `https://api.endorser.ch`). | -| `FCM_TOKEN_DATA_DIR` | Directory for the SQLite database file `notify.sqlite` (default: `./data`). | +| `NOTIFY_DATA_DIR` | Directory for the SQLite database file `notify.sqlite` (default: `./data`). | diff --git a/src/db/sqlite.ts b/src/db/sqlite.ts index d75728b..f29453d 100644 --- a/src/db/sqlite.ts +++ b/src/db/sqlite.ts @@ -3,7 +3,7 @@ import path from "node:path"; import Database from "better-sqlite3"; const dataDir = - process.env.FCM_TOKEN_DATA_DIR ?? path.join(process.cwd(), "data"); + process.env.NOTIFY_DATA_DIR ?? path.join(process.cwd(), "data"); const dbFile = path.join(dataDir, "notify.sqlite"); const SCHEMA_SQL = `