| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- // Disable the following rule because this file is the intended place to declare
- // and load all env variables.
- /* eslint-disable n/no-process-env */
- // Disable the following rule because variables in this file are only loaded at
- // runtime and do not influence the build outputs, thus they need not be
- // declared to turbo for it to be able to cache build outputs correctly.
- /* eslint-disable turbo/no-undeclared-env-vars */
- import "server-only";
- /**
- * Throw if the env var `key` is not set (at either runtime or build time).
- */
- const demand = (key: string): string => {
- const value = process.env[key];
- if (value === undefined || value === "") {
- throw new MissingEnvironmentError(key);
- } else {
- return value;
- }
- };
- /**
- * Indicates that this server is the live customer-facing production server.
- */
- export const IS_PRODUCTION_SERVER = process.env.VERCEL_ENV === "production";
- /**
- * Throw if the env var `key` is not set in the live customer-facing production
- * server, but allow it to be unset in any other environment.
- */
- const demandInProduction = IS_PRODUCTION_SERVER
- ? demand
- : (key: string) => process.env[key];
- export const GOOGLE_ANALYTICS_ID = demandInProduction("GOOGLE_ANALYTICS_ID");
- export const AMPLITUDE_API_KEY = demandInProduction("AMPLITUDE_API_KEY");
- class MissingEnvironmentError extends Error {
- constructor(name: string) {
- super(`Missing environment variable: ${name}!`);
- this.name = "MissingEnvironmentError";
- }
- }
|