nitrojs / nitrojs/nitro

runtimeConfig schema validation

Open
#3,522 0 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement v2
Dominant language
TypeScript
Stars
11.2k
Forks
899
Avg merge
2d 24m
Merged PRs (30d)
40

Description

Describe the feature

Instead of defining overridable empty values inside the (nitro|nuxt).config.ts file, we should be able to define a schema using a validation library like zod or valibot.

Actual overridable values runtimeConfig

//https://nitro.unjs.io/config
export default defineNitroConfig({
  srcDir: "server",

  runtimeConfig: {
    betterAuth: {
      secret: "",
      url: "",
    },
    turnstile: {
      secretKey: "",
    },
    cronSecret: "",
    upstash: {
      redis: {
        url: "",
        token: "",
      },
    },
    posthog: {
      apiKey: "",
      apiHost: "",
    },
  },
});

Schema based runtimeConfig

import { z } from "zod";

//https://nitro.unjs.io/config
export default defineNitroConfig({
  srcDir: "server",

  runtimeConfig: {
    betterAuth: {
      secret: z.string().min(32).max(32),
      url: z.string().url(),
    },
    turnstile: {
      secretKey: z.string().min(1),
    },
    cronSecret: z.string().min(1),
    upstash: {
      redis: {
        url: z.string().min(1),
        token: z.string().min(1),
      },
    },
    posthog: {
      apiKey: z.string().min(1),
      apiHost: z.string().min(1),
    },
  },
});
Additional information
  • Would you be willing to help implement this feature?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the (nitro|nuxt).config.ts runtimeConfig examples and the Nitro configuration documentation linked in the issue. Define how schema values from libraries such as zod or valibot should be accepted and when runtime values are validated; done means the documented configuration supports the shown schema-based form with clear validation behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.