fix: use string comparison for checking database_less

This commit is contained in:
Tianzhou Chen
2023-06-05 23:57:43 +08:00
parent f3943183ab
commit 5d69a0fdaa
2 changed files with 14 additions and 10 deletions

4
process.d.ts vendored
View File

@ -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;

View File

@ -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(),
},
};