mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-13 21:05:22 +00:00
Massage environment variables from strings to numbers (#234)
This commit is contained in:
parent
e8667da1ca
commit
583df1dd77
2 changed files with 18 additions and 8 deletions
|
|
@ -5,6 +5,11 @@ import dotenv from 'dotenv';
|
||||||
// Booleans are specified as 'true' or 'false' strings.
|
// Booleans are specified as 'true' or 'false' strings.
|
||||||
const booleanSchema = z.enum(["true", "false"]);
|
const booleanSchema = z.enum(["true", "false"]);
|
||||||
|
|
||||||
|
// Numbers are treated as strings in .env files.
|
||||||
|
// coerce helps us convert them to numbers.
|
||||||
|
// @see: https://zod.dev/?id=coercion-for-primitives
|
||||||
|
const numberSchema = z.coerce.number();
|
||||||
|
|
||||||
dotenv.config({
|
dotenv.config({
|
||||||
path: './.env',
|
path: './.env',
|
||||||
});
|
});
|
||||||
|
|
@ -28,7 +33,7 @@ export const env = createEnv({
|
||||||
FALLBACK_GITLAB_TOKEN: z.string().optional(),
|
FALLBACK_GITLAB_TOKEN: z.string().optional(),
|
||||||
FALLBACK_GITEA_TOKEN: z.string().optional(),
|
FALLBACK_GITEA_TOKEN: z.string().optional(),
|
||||||
|
|
||||||
REDIS_URL: z.string().url(),
|
REDIS_URL: z.string().url().default("redis://localhost:6379"),
|
||||||
|
|
||||||
SENTRY_BACKEND_DSN: z.string().optional(),
|
SENTRY_BACKEND_DSN: z.string().optional(),
|
||||||
SENTRY_ENVIRONMENT: z.string().optional(),
|
SENTRY_ENVIRONMENT: z.string().optional(),
|
||||||
|
|
@ -36,8 +41,8 @@ export const env = createEnv({
|
||||||
LOGTAIL_TOKEN: z.string().optional(),
|
LOGTAIL_TOKEN: z.string().optional(),
|
||||||
LOGTAIL_HOST: z.string().url().optional(),
|
LOGTAIL_HOST: z.string().url().optional(),
|
||||||
|
|
||||||
INDEX_CONCURRENCY_MULTIPLE: z.number().optional(),
|
INDEX_CONCURRENCY_MULTIPLE: numberSchema.optional(),
|
||||||
DATABASE_URL: z.string().url(),
|
DATABASE_URL: z.string().url().default("postgresql://postgres:postgres@localhost:5432/postgres")
|
||||||
},
|
},
|
||||||
runtimeEnv: process.env,
|
runtimeEnv: process.env,
|
||||||
emptyStringAsUndefined: true,
|
emptyStringAsUndefined: true,
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,17 @@ import { z } from "zod";
|
||||||
// Booleans are specified as 'true' or 'false' strings.
|
// Booleans are specified as 'true' or 'false' strings.
|
||||||
const booleanSchema = z.enum(["true", "false"]);
|
const booleanSchema = z.enum(["true", "false"]);
|
||||||
|
|
||||||
|
// Numbers are treated as strings in .env files.
|
||||||
|
// coerce helps us convert them to numbers.
|
||||||
|
// @see: https://zod.dev/?id=coercion-for-primitives
|
||||||
|
const numberSchema = z.coerce.number();
|
||||||
|
|
||||||
export const env = createEnv({
|
export const env = createEnv({
|
||||||
server: {
|
server: {
|
||||||
// Zoekt
|
// Zoekt
|
||||||
ZOEKT_WEBSERVER_URL: z.string().url(),
|
ZOEKT_WEBSERVER_URL: z.string().url().default("http://localhost:6070"),
|
||||||
SHARD_MAX_MATCH_COUNT: z.number().default(10000),
|
SHARD_MAX_MATCH_COUNT: numberSchema.default(10000),
|
||||||
TOTAL_MAX_MATCH_COUNT: z.number().default(100000),
|
TOTAL_MAX_MATCH_COUNT: numberSchema.default(100000),
|
||||||
|
|
||||||
// Auth
|
// Auth
|
||||||
AUTH_SECRET: z.string(),
|
AUTH_SECRET: z.string(),
|
||||||
|
|
@ -31,7 +36,7 @@ export const env = createEnv({
|
||||||
STRIPE_ENABLE_TEST_CLOCKS: booleanSchema.default('false'),
|
STRIPE_ENABLE_TEST_CLOCKS: booleanSchema.default('false'),
|
||||||
|
|
||||||
// Misc
|
// Misc
|
||||||
CONFIG_MAX_REPOS_NO_TOKEN: z.number().default(500),
|
CONFIG_MAX_REPOS_NO_TOKEN: numberSchema.default(500),
|
||||||
SOURCEBOT_ROOT_DOMAIN: z.string().default("localhost:3000"),
|
SOURCEBOT_ROOT_DOMAIN: z.string().default("localhost:3000"),
|
||||||
NODE_ENV: z.enum(["development", "test", "production"]),
|
NODE_ENV: z.enum(["development", "test", "production"]),
|
||||||
SOURCEBOT_TELEMETRY_DISABLED: booleanSchema.default('false'),
|
SOURCEBOT_TELEMETRY_DISABLED: booleanSchema.default('false'),
|
||||||
|
|
@ -45,7 +50,7 @@ export const env = createEnv({
|
||||||
|
|
||||||
// Misc
|
// Misc
|
||||||
NEXT_PUBLIC_SOURCEBOT_VERSION: z.string().default('unknown'),
|
NEXT_PUBLIC_SOURCEBOT_VERSION: z.string().default('unknown'),
|
||||||
NEXT_PUBLIC_POLLING_INTERVAL_MS: z.number().default(5000),
|
NEXT_PUBLIC_POLLING_INTERVAL_MS: numberSchema.default(5000),
|
||||||
},
|
},
|
||||||
// For Next.js >= 13.4.4, you only need to destructure client variables:
|
// For Next.js >= 13.4.4, you only need to destructure client variables:
|
||||||
experimental__runtimeEnv: {
|
experimental__runtimeEnv: {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue