chore: auto-load .env for local backend start/migrate scripts

This commit is contained in:
Bastian Wagner
2026-08-17 16:42:57 +02:00
parent 981cecbcbd
commit 698a2180aa
2 changed files with 13 additions and 11 deletions

View File

@@ -23,21 +23,22 @@ pnpm dev:infra
`pnpm dev:infra` starts local PostgreSQL/Redis (see `compose.dev.yml`); `pnpm dev:infra:down` stops them.
Set the required OIDC env vars once per shell before running the backend. **`OIDC_CLIENT_SECRET` is a real secret — set it directly in your own shell, never commit it, never paste it into a shared/logged terminal.** `OIDC_AUDIENCE` should be set to the same value as `OIDC_CLIENT_ID` unless your IdP issues a distinct API audience.
Create a **`.env` file at the repository root** (already gitignored, never committed) with the required values. `backend`'s `start:api`/`start:worker`/`migrate` scripts load it automatically via Node's `--env-file-if-exists` — no manual `export` needed. **`OIDC_CLIENT_SECRET` is a real secret — put it only in this local, gitignored file, never in `.env.example`, never pasted into a shared/logged terminal.** `OIDC_AUDIENCE` should be set to the same value as `OIDC_CLIENT_ID` unless your IdP issues a distinct API audience.
```bash
export DATABASE_URL=postgresql://travel_planner:travel_planner_dev@localhost:5432/travel_planner
export REDIS_URL=redis://localhost:6379
export OIDC_ISSUER=https://auth.forgecore.work
export OIDC_CLIENT_ID=client_a297fd8d9c1f47a79d3600ea0c96984
export OIDC_AUDIENCE=$OIDC_CLIENT_ID
export OIDC_CLIENT_SECRET=<your-client-secret> # never commit this value
```dotenv
DATABASE_URL=postgresql://travel_planner:travel_planner_dev@localhost:5432/travel_planner
REDIS_URL=redis://localhost:6379
OIDC_ISSUER=https://auth.forgecore.work
OIDC_CLIENT_ID=client_a297fd8d9c1f47a79d3600ea0c96984
OIDC_AUDIENCE=client_a297fd8d9c1f47a79d3600ea0c96984
OIDC_CLIENT_SECRET=<your-client-secret>
```
Run pending migrations against the dev database (first time only), then start the API and frontend:
```bash
pnpm --filter backend build:api && node backend/dist/apps/api/src/migration.js
pnpm --filter backend build:api
pnpm --filter backend migrate
pnpm --filter backend start:api
pnpm --filter frontend start
```

View File

@@ -13,8 +13,9 @@
"start": "nest start api",
"start:dev": "nest start api --watch",
"start:debug": "nest start api --debug --watch",
"start:api": "node dist/apps/api/src/main.js",
"start:worker": "node dist/apps/worker/src/main.js",
"start:api": "node --env-file-if-exists=../.env dist/apps/api/src/main.js",
"start:worker": "node --env-file-if-exists=../.env dist/apps/worker/src/main.js",
"migrate": "node --env-file-if-exists=../.env dist/apps/api/src/migration.js",
"lint": "eslint \"{apps,libs}/**/*.ts\" --fix",
"test": "jest --runInBand",
"test:watch": "jest --watch",