Files
certd/packages/ui/certd-client/src/utils/util.env.ts
T

44 lines
864 B
TypeScript
Raw Normal View History

2023-06-25 15:30:18 +08:00
// @ts-ignore
2023-05-09 09:49:42 +08:00
import _ from "lodash";
2023-06-25 15:30:18 +08:00
export function getEnvValue(key: string) {
2023-01-29 13:44:19 +08:00
// @ts-ignore
return import.meta.env["VITE_APP_" + key];
}
export class EnvConfig {
2023-06-25 15:30:18 +08:00
API: string;
MODE: string;
STORAGE: string;
TITLE: string;
PM_ENABLED: string;
2023-01-29 13:44:19 +08:00
constructor() {
this.init();
}
init() {
// @ts-ignore
_.forEach(import.meta.env, (value, key) => {
if (key.startsWith("VITE_APP")) {
key = key.replace("VITE_APP_", "");
2023-06-25 15:30:18 +08:00
//@ts-ignore
2023-01-29 13:44:19 +08:00
this[key] = value;
}
});
// @ts-ignore
this.MODE = import.meta.env.MODE;
}
2023-06-25 15:30:18 +08:00
get(key: string, defaultValue: string) {
//@ts-ignore
2023-01-29 13:44:19 +08:00
return this[key] ?? defaultValue;
}
isDev() {
return this.MODE === "development" || this.MODE === "debug";
}
isProd() {
return this.MODE === "production";
}
}
export const env = new EnvConfig();