diff --git a/process.d.ts b/process.d.ts index 7d75ecf..ad5d652 100644 --- a/process.d.ts +++ b/process.d.ts @@ -2,10 +2,10 @@ declare namespace NodeJS { export interface ProcessEnv { // Required. Node environment. NODE_ENV: string; - // Optional. Set to true to disable the database. Defaults to false. + // Optional. Set to "true" to disable the database. Need to use string as env is always string. // We can't prefix DATABASE_URL with NEXT_PUBLIC_ because it contains sensitive information that // should not be exposed to the client. - NEXT_PUBLIC_DATABASE_LESS: boolean; + NEXT_PUBLIC_DATABASE_LESS: string; // Required if NEXT_PUBLIC_DATABASE_LESS is false. Postgres database connection string to store // the data. e.g. postgresql://postgres:YOUR_PASSWORD@localhost:5432/sqlchat?schema=sqlchat DATABASE_URL: string; diff --git a/src/utils/feature.ts b/src/utils/feature.ts index ff5dcbe..a84b50a 100644 --- a/src/utils/feature.ts +++ b/src/utils/feature.ts @@ -1,19 +1,23 @@ type FeatureType = "debug" | "account" | "payment" | "quota" | "collect"; +function databaseLess() { + return process.env.NEXT_PUBLIC_DATABASE_LESS == "true"; +} + const matrix: { [key: string]: { [feature: string]: boolean } } = { development: { debug: true, - account: !process.env.NEXT_PUBLIC_DATABASE_LESS, - payment: !process.env.NEXT_PUBLIC_DATABASE_LESS, - quota: !process.env.NEXT_PUBLIC_DATABASE_LESS, - collect: !process.env.NEXT_PUBLIC_DATABASE_LESS, + account: !databaseLess(), + payment: !databaseLess(), + quota: !databaseLess(), + collect: !databaseLess(), }, production: { debug: false, - account: !process.env.NEXT_PUBLIC_DATABASE_LESS, - payment: !process.env.NEXT_PUBLIC_DATABASE_LESS, - quota: !process.env.NEXT_PUBLIC_DATABASE_LESS, - collect: !process.env.NEXT_PUBLIC_DATABASE_LESS, + account: !databaseLess(), + payment: !databaseLess(), + quota: !databaseLess(), + collect: !databaseLess(), }, };