import { EnvEmitter } from "../utils/Events";
import { exitProcess } from "../utils/Process";
import { log } from "../utils/Function";
import { ExitCodes } from "./Errors";
import { InDev } from "./Env";
export function CheckEnv(Env_Field: string, exitCode: ICode) {
if (!process.env[Env_Field]) {
log(`🔴 Failed on loading env field => '${Env_Field}'`);
exitProcess(exitCode, { field: Env_Field });
}
log(`🟢 Checking env field => '${Env_Field}' : ${process.env[Env_Field]}`);
return process.env[Env_Field] as string;
}
// checkable env
log("---------------------------- Necessary ENV ----------------------------");
export const MYSQL_HOST = CheckEnv("MYSQL_HOST", ExitCodes.ENV_ERROR_COULDNT_FIND_FIELD);
export const MYSQL_USER = CheckEnv("MYSQL_USER", ExitCodes.ENV_ERROR_COULDNT_FIND_FIELD);
export const MYSQL_PASSWORD = CheckEnv("MYSQL_PASSWORD", ExitCodes.ENV_ERROR_COULDNT_FIND_FIELD);
export const MYSQL_DATABASE = CheckEnv("MYSQL_DATABASE", ExitCodes.ENV_ERROR_COULDNT_FIND_FIELD);
export const JWT_SECRET = CheckEnv("BACK_SECRET", ExitCodes.ENV_ERROR_COULDNT_FIND_FIELD);
export const EmailUser = CheckEnv("SMTP_MAIL", ExitCodes.ENV_ERROR_COULDNT_FIND_FIELD);
export const EmailPass = CheckEnv("SMTP_PASSWORD", ExitCodes.ENV_ERROR_COULDNT_FIND_FIELD);
export const CloudinaryName = CheckEnv("CLOUDINARY_NAME", ExitCodes.ENV_ERROR_COULDNT_FIND_FIELD);
export const CloudinaryKey = CheckEnv("CLOUDINARY_KEY", ExitCodes.ENV_ERROR_COULDNT_FIND_FIELD);
export const CloudSecret = CheckEnv("CLOUDINARY_SECRET", ExitCodes.ENV_ERROR_COULDNT_FIND_FIELD);
// export const ORIGINS = !InDev ? CheckEnv("CORPS_ORIGINS", ExitCodes.ENV_ERROR_COULDNT_FIND_FIELD)?.split(" ") : [];
export const ORIGINS = !InDev ? CheckEnv("CORPS_ORIGINS", ExitCodes.ENV_ERROR_COULDNT_FIND_FIELD) : "*";
log("--------------------------------------------------------\n");
EnvEmitter.emit("loaded");