feat(app): bindAll() now checks NODE_ENV in addition to USE_DEV_SEED

Three-rule resolution order in bindAll() (first match wins):

  1. USE_DEV_SEED === 'true'   → bindAllDevSeed (explicit override)
  2. NODE_ENV    === 'production' → bindAllProduction
  3. otherwise                  → bindAllDevSeed (developer default)

Rationale: 'pnpm dev' should boot the app without requiring Payload to
be running locally — dev seed is the more useful default for non-
production environments. Production servers explicitly set
NODE_ENV=production and get the real binding. The USE_DEV_SEED override
remains the escape hatch (force seed in any NODE_ENV — e.g. staging
preview, design review).

bind-production.test.ts grows from 3 tests to 8 — covers the dispatcher
matrix:
- USE_DEV_SEED='true' wins even when NODE_ENV='production'
- NODE_ENV='production' (no override) → production
- NODE_ENV='development' → dev seed (default)
- NODE_ENV unset → dev seed (default)
- USE_DEV_SEED='false' treated as not-set (only the literal 'true' triggers)
- Pre-existing 'binds all five repos' test now also asserts bindProductionMedia

di-explainer.html conditions table + mode flag strings updated to match
the new three-rule logic.
This commit is contained in:
2026-05-06 19:32:00 +02:00
parent 61dde18b53
commit 6bf19f35c5
3 changed files with 136 additions and 12 deletions

View File

@@ -46,16 +46,34 @@ export async function bindAllDevSeed(): Promise<void> {
}
/**
* Boot dispatcher: pick the binder based on `process.env.USE_DEV_SEED`.
* Idempotent — guarded by the same `bound` flag as `bindAllProduction`.
* Boot dispatcher: pick the binder based on the environment.
*
* Call this from server entry points (route handlers, page server components)
* before resolving any feature controller.
* Resolution order (first match wins):
*
* 1. `USE_DEV_SEED === "true"` → dev seed (explicit override; works in
* any NODE_ENV — useful for staging,
* storybook, design review).
* 2. `NODE_ENV === "production"` → real Payload via bindAllProduction(config).
* 3. otherwise → dev seed (developer-friendly default;
* `pnpm dev` works without Payload booted).
*
* To force production locally without changing NODE_ENV, set
* `USE_DEV_SEED=false` is NOT enough — set `NODE_ENV=production` instead.
*
* Idempotent: guarded by the same `bound` flag the underlying binders share.
* Call from server entry points (route handlers, page server components,
* tRPC route handlers) before resolving any feature controller.
*/
export async function bindAll(): Promise<void> {
if (process.env.USE_DEV_SEED === "true") {
await bindAllDevSeed();
return;
}
await bindAllProduction();
if (process.env.NODE_ENV === "production") {
await bindAllProduction();
return;
}
// Default for dev / test / unset NODE_ENV: dev seed so the app boots
// without Payload running.
await bindAllDevSeed();
}