Fix:Implement function to handle boolean strings

This commit is contained in:
Kevin Carrera Calzado 2024-01-24 11:11:18 -05:00
parent 06ad2249d6
commit 7b26b029de
2 changed files with 14 additions and 11 deletions

View File

@ -2,6 +2,7 @@ import { devFragment } from '@/config/fragments/dev';
import { dockerFragment } from '@/config/fragments/docker';
import { createConfigLoader } from 'neat-config';
import { z } from 'zod';
import { booleanSchema } from './schema';
const fragments = {
dev: devFragment,
@ -13,7 +14,7 @@ export const ormConfigSchema = z.object({
// connection URL for postgres database
connection: z.string(),
// whether to use SSL for the connection
ssl: z.coerce.boolean().default(false),
ssl: booleanSchema,
}),
});

View File

@ -1,5 +1,7 @@
import { z } from 'zod';
export const booleanSchema = z.preprocess((val) => val === 'true', z.boolean());
export const configSchema = z.object({
server: z
.object({
@ -11,13 +13,13 @@ export const configSchema = z.object({
// disable cross origin restrictions, allow any site.
// overwrites the cors option above
allowAnySite: z.coerce.boolean().default(false),
allowAnySite: booleanSchema,
// should it trust reverse proxy headers? (for ip gathering)
trustProxy: z.coerce.boolean().default(false),
trustProxy: booleanSchema,
// should it trust cloudflare headers? (for ip gathering, cloudflare has priority)
trustCloudflare: z.coerce.boolean().default(false),
trustCloudflare: booleanSchema,
// prefix for where the instance is run on. for example set it to /backend if you're hosting it on example.com/backend
// if this is set, do not apply url rewriting before proxing
@ -30,7 +32,7 @@ export const configSchema = z.object({
format: z.enum(['json', 'pretty']).default('pretty'),
// show debug logs?
debug: z.coerce.boolean().default(false),
debug: booleanSchema,
})
.default({}),
postgres: z.object({
@ -38,19 +40,19 @@ export const configSchema = z.object({
connection: z.string(),
// run all migrations on boot of the application
migrateOnBoot: z.coerce.boolean().default(false),
migrateOnBoot: booleanSchema,
// try to sync the schema on boot, useful for development
// will always keep the database schema in sync with the connected database
// it is extremely destructive, do not use it EVER in production
syncSchema: z.coerce.boolean().default(false),
syncSchema: booleanSchema,
// Enable debug logging for MikroORM - Outputs queries and entity management logs
// Do NOT use in production, leaks all sensitive data
debugLogging: z.coerce.boolean().default(false),
debugLogging: booleanSchema,
// Enable SSL for the postgres connection
ssl: z.coerce.boolean().default(false),
ssl: booleanSchema,
}),
crypto: z.object({
// session secret. used for signing session tokens
@ -65,7 +67,7 @@ export const configSchema = z.object({
captcha: z
.object({
// enabled captchas on register
enabled: z.coerce.boolean().default(false),
enabled: booleanSchema,
// captcha secret
secret: z.string().min(1).optional(),
@ -76,7 +78,7 @@ export const configSchema = z.object({
ratelimits: z
.object({
// enabled captchas on register
enabled: z.coerce.boolean().default(false),
enabled: booleanSchema,
redisUrl: z.string().optional(),
})
.default({}),