Initial commit
This commit is contained in:
25
packages/config/src/index.ts
Normal file
25
packages/config/src/index.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { z } from "zod";
|
||||
|
||||
const envSchema = z.object({
|
||||
APP_NAME: z.string().min(1).default("porthole"),
|
||||
NEXT_PUBLIC_APP_NAME: z.string().min(1).optional()
|
||||
});
|
||||
|
||||
let cachedEnv: z.infer<typeof envSchema> | undefined;
|
||||
|
||||
export function getEnv() {
|
||||
if (cachedEnv) return cachedEnv;
|
||||
|
||||
const parsed = envSchema.safeParse(process.env);
|
||||
if (!parsed.success) {
|
||||
throw new Error(`Invalid environment variables: ${parsed.error.message}`);
|
||||
}
|
||||
|
||||
cachedEnv = parsed.data;
|
||||
return cachedEnv;
|
||||
}
|
||||
|
||||
export function getAppName() {
|
||||
const env = getEnv();
|
||||
return env.NEXT_PUBLIC_APP_NAME ?? env.APP_NAME;
|
||||
}
|
||||
Reference in New Issue
Block a user