Files
cal.diy/apps/api/v2/src/env.ts
T
Erik 1cfd2f7053 feat: Billing Service (#14756)
* chore: Billing Service

* chore: others

* chore: don't type

* chore: typo

* chore: use proper wh secret

* chore: updates

* chore: lockfile

* chore: docs and comment out

* chore: updates and include plan

* chore: config

* chore: bring back alias

* chore: update lockfile

* chore: refactor

* chore: default none plan in db

* chore: read from env vars

* chore: feedback

* chore: remove json config

* chore: proper type
2024-04-30 20:02:04 +00:00

32 lines
774 B
TypeScript

import { logLevels } from "@/lib/logger";
export type Environment = {
NODE_ENV: "development" | "production";
API_PORT: string;
API_URL: string;
DATABASE_READ_URL: string;
DATABASE_WRITE_URL: string;
NEXTAUTH_SECRET: string;
DATABASE_URL: string;
JWT_SECRET: string;
SENTRY_DSN: string;
LOG_LEVEL: keyof typeof logLevels;
REDIS_URL: string;
STRIPE_API_KEY: string;
STRIPE_WEBHOOK_SECRET: string;
WEB_APP_URL: string;
};
export const getEnv = <K extends keyof Environment>(key: K, fallback?: Environment[K]): Environment[K] => {
const value = process.env[key] as Environment[K] | undefined;
if (!value) {
if (fallback) {
return fallback;
}
throw new Error(`Missing environment variable: ${key}.`);
}
return value;
};