server/env.ts

Base server environment schema and validation.

Provides BaseServerEnv — a shared @fuzdev/fuz_schema object schema for common server env vars that apps can use directly or extend with app-specific fields.

Generic env loading lives in env/load.ts, and the value schemas (env_integer, EnvStringbool) in env/env_schemas.ts.

view source

Declarations
#

4 declarations

BaseServerEnv
#

server/env.ts view source

value + type

{ NODE_ENV: "development" | "production"; PORT: number; HOST: string; DATABASE_URL: string; SECRET_FUZ_COOKIE_KEYS: string; FUZ_ALLOWED_ORIGINS: string; FUZ_ALLOW_ORIGIN_WILDCARDS?: "true" | ... 1 more ... | undefined; FUZ_BOOTSTRAP_TOKEN_PATH?: string | undefined; FUZ_DB_CHECKOUT_TIMEOUT_MS?: number | undefined; FU... import {BaseServerEnv} from '@fuzdev/fuz_app/server/env.js';

Base schema for server environment variables, a strict object.

Declares only what the spine reads — server config, database and its pool checkout bounds, cookie keys, allowed origins and the wildcard opt-in, and the bootstrap token path — matching the Rust spine's BaseServerEnv. The numeric vars read as the Rust twin reads them (env_integer: trimmed, then decimal digits after at most one +, so 5e3 and a blank value are refused on both, as is one out of range). Anything else (fact storage, X-Accel delivery, public URLs) is the app's own var: extend by spreading def into a new object, object({...BaseServerEnv.def, MY_VAR: ...}).

Each field's description and sensitivity are meta, read by env_schema_to_surface.

NODE_ENV

type "development" | "production"

PORT

type number

HOST

type string

DATABASE_URL

type string

SECRET_FUZ_COOKIE_KEYS

type string

FUZ_ALLOWED_ORIGINS

type string

FUZ_ALLOW_ORIGIN_WILDCARDS?

type "true" | "false"

FUZ_BOOTSTRAP_TOKEN_PATH?

type string

FUZ_DB_CHECKOUT_TIMEOUT_MS?

type number

FUZ_DB_AUDIT_CHECKOUT_TIMEOUT_MS?

type number

ServerEnvValidationError
#

server/env.ts view source

ServerEnvValidationError import type {ServerEnvValidationError} from '@fuzdev/fuz_app/server/env.js';

Error from validate_server_env — keyring or origin validation failed.

field

type "SECRET_FUZ_COOKIE_KEYS" | "FUZ_ALLOWED_ORIGINS"

errors

type string[]

validate_server_env
#

server/env.ts view source

(env: { NODE_ENV: "development" | "production"; PORT: number; HOST: string; DATABASE_URL: string; SECRET_FUZ_COOKIE_KEYS: string; FUZ_ALLOWED_ORIGINS: string; FUZ_ALLOW_ORIGIN_WILDCARDS?: "true" | ... 1 more ... | undefined; FUZ_BOOTSTRAP_TOKEN_PATH?: string | undefined; FUZ_DB_CHECKOUT_TIMEOUT_MS?: number | undefined; FUZ_DB_AUDIT_CHECKOUT_TIMEOUT_MS?: number | undefined; }): Result<...> import {validate_server_env} from '@fuzdev/fuz_app/server/env.js';

Validate a loaded BaseServerEnv and produce the artifacts needed for server init.

Handles keyring validation, origin parsing (every refused allowlist entry is reported, each on its own line), the wildcard opt-in (a wildcard entry without FUZ_ALLOW_ORIGIN_WILDCARDS=true is refused with admit_origin_wildcards' text, as create_app_server would), and bootstrap token path extraction. Returns a Result so callers handle errors their own way (exit, logging, etc).

env

a loaded and validated BaseServerEnv

returns

Result

{ok: true, keyring, allowed_origins, allow_origin_wildcards, bootstrap_token_path} or {ok: false, field, errors}

ValidatedServerEnv
#

server/env.ts view source

ValidatedServerEnv import type {ValidatedServerEnv} from '@fuzdev/fuz_app/server/env.js';

Validated server env config — the artifacts create_app_server() needs.

keyring

type Keyring

allowed_origins

type RegExp[]

allow_origin_wildcards

FUZ_ALLOW_ORIGIN_WILDCARDS=true — pass to create_app_server's allow_origin_wildcards, which refuses a wildcard entry without it.

type boolean

bootstrap_token_path

type string | null

Depends on
#

Imported by
#