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

48 lines
1014 B
TypeScript
Raw Normal View History

2025-06-29 14:09:09 +08:00
import { forEach } from "lodash-es";
export function getEnvValue(key: string) {
// @ts-ignore
return import.meta.env["VITE_APP_" + key];
}
2023-01-29 13:44:19 +08:00
export class EnvConfig {
2024-09-23 11:27:53 +08:00
MODE: string = import.meta.env.MODE;
2025-08-09 23:41:59 +08:00
API: string;
STORAGE: string;
TITLE: string;
SLOGAN: string;
LOGO: string;
LOGIN_LOGO: string;
ICP_NO: string;
COPYRIGHT_YEAR: string;
COPYRIGHT_NAME: string;
COPYRIGHT_URL: string;
PM_ENABLED: string;
VIP_PRODUCT_URL: string;
2023-01-29 13:44:19 +08:00
2025-08-09 23:41:59 +08:00
constructor() {
this.init();
}
init() {
const env = import.meta.env;
2024-09-23 11:27:53 +08:00
for (const key in this) {
2025-08-09 23:41:59 +08:00
const metaKey = "VITE_APP_" + key;
if (this.hasOwnProperty(key) && env.hasOwnProperty(metaKey)) {
this[key] = env[metaKey];
2023-01-29 13:44:19 +08:00
}
2024-09-23 11:27:53 +08:00
}
2023-01-29 13:44:19 +08:00
}
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();