Validate env vars on boot up

This commit is contained in:
Kalle (Sendou) 2021-10-24 15:42:09 +03:00
parent 86e55f229b
commit 7ba695f4e3

View File

@ -12,6 +12,8 @@ const app = new App();
const PORT = 3001;
validateEnvVars();
passport.use(
new DiscordStrategy(
{
@ -65,3 +67,22 @@ app
.listen(PORT, () =>
console.log(`Server ready at: https://localhost:${PORT}`)
);
function validateEnvVars() {
const logInEnvVars = [
"DISCORD_CLIENT_ID",
"DISCORD_CLIENT_SECRET",
"DISCORD_CALLBACK_URL",
].filter((envVar) => !process.env[envVar]);
if (logInEnvVars.length === 0) return;
if (process.env.NODE_ENV === "development") {
console.warn(
"Missing env vars for testing logging in:",
logInEnvVars.join(", ")
);
} else {
throw new Error("Missing env vars for logging in");
}
}