27 lines
959 B
TypeScript
27 lines
959 B
TypeScript
/** The predefined environment values */
|
|
import * as fs from "fs";
|
|
|
|
const envValue: string[] = [
|
|
"DB_NAME", "DB_USER", "DB_PASS", "DB_HOST", "API_PORT", "SHORTENER_PORT", "CDN_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();
|
|
} |