Backend/util/envCheck.ts

26 lines
941 B
TypeScript

/** The predefined environment values */
import * as fs from "fs";
const envValue: string[] = [
"MONGOOSE_STRING", "API_PORT", "SHORTENER_PORT", "CDN_PORT", "AS_PORT", "DC_CLIENT", "DC_SECRET", "DC_REDIRECT_URI", "GCLOUD_STORAGE_BUCKET"
]
/** Checks if the provided value is registered in process.env */
const isRegistered = (value: string) => process.env[value];
/** Checks if the gbucket.json file exists */
const checkGoogleAuthentication = () => {
if (!fs.existsSync(process.cwd() + "/gbucket.json")) {
console.warn("[ContentDelivery] Could not find gbucket.json. Content delivery disabled.");
process.env.DISABLE_CONTENT_DELIVERY = "true"
}
}
/** Validates the .env file */
module.exports.validate = () => {
for (let value of envValue) {
if (!isRegistered(value)) throw new Error(`Please register the environment value '${value}' in your .env file`);
}
checkGoogleAuthentication();
}