[]previous and next page

defineEnv

Describes the environment of the app.

Describes the environment of the app. The handler validates it at startup, so a missing secret stops the server before it serves a request. Variables named DUSK_PUBLIC_* are the only ones a client bundle may read; everything else is server-only.

Import#

ts
import { defineEnv } from "@shadow-js/dusk/server";

Signature#

ts
function defineEnv<const S extends EnvShape>(
  shape: S,
  options: EnvOptions = {},
): EnvSchema<S>

Parameters#

Name Description
shape Variable name to description.
options The app's public prefixes (env.public.prefixes of dusk.config.ts), beside DUSK_PUBLIC_.

Returns#

The schema; pass it as createHandler({ env }) or call parse yourself.

Throws#

  • TypeError for an invalid name, or a field marked secret whose name has a public prefix ([ENV_SECRET_PUBLIC]). The schema module runs on the server only: the build does not evaluate it, so this check runs when the module loads.

Examples#

ts
const env = defineEnv({
  DATABASE_URL: { type: "url", protocols: ["postgres:"] },
  PORT: { type: "number", integer: true, default: 3000 },
  DUSK_PUBLIC_API_URL: { type: "url" },
}, { publicPrefixes: ["NEXT_PUBLIC_"] });