From 97b1939c384bf4785034310067ed9d8a16b8a92f Mon Sep 17 00:00:00 2001 From: Bowden Date: Wed, 10 Jan 2018 09:28:58 -0800 Subject: [PATCH] WIP - still need to use NO_DATABASE env var to safely avoid db errors --- .vscode/settings.json | 5 ++++- src/app.ts | 2 +- src/util/secrets.ts | 9 ++++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 911ff07..961d20b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -13,6 +13,9 @@ "cSpell.words": [ "definitelytyped", "reddit", - "subreddit" + "resave", + "signup", + "subreddit", + "xframe" ] } \ No newline at end of file diff --git a/src/app.ts b/src/app.ts index da41b25..8f3d58f 100644 --- a/src/app.ts +++ b/src/app.ts @@ -36,7 +36,7 @@ mongoose.connect(mongoUrl, {useMongoClient: true}).then( () => { /** ready to use. The `mongoose.connect()` promise resolves to undefined. */ }, ).catch(err => { console.log("MongoDB connection error. Please make sure MongoDB is running. " + err); - // process.exit(); + process.exit(); }); // Express configuration diff --git a/src/util/secrets.ts b/src/util/secrets.ts index bc6d27a..fa143e4 100644 --- a/src/util/secrets.ts +++ b/src/util/secrets.ts @@ -5,13 +5,20 @@ import * as fs from "fs"; if (fs.existsSync(".env")) { logger.debug("Using .env file to supply config environment variables"); dotenv.config({ path: ".env" }); -} else { +} else if (fs.existsSync(".env.example")) { logger.debug("Using .env.example file to supply config environment variables"); dotenv.config({ path: ".env.example" }); // you can delete this after you create your own .env file! +} else { + logger.error("This project requires a .env file to configure environment variables"); } export const ENVIRONMENT = process.env.NODE_ENV; const prod = ENVIRONMENT === "production"; // Anything else is treated as 'dev' +// Delete this after you've added a database to the project +if (process.env["NO_DATABASE_SETUP"] === "true") { + logger.debug(`No database detected. Either follow steps in the README to set up a MongoDB, + or delete the NO_DATABASE_SETUP setting from your .env settings file if you already have one setup.`); +} export const SESSION_SECRET = process.env["SESSION_SECRET"]; export const MONGODB_URI = prod ? process.env["MONGODB_URI"] : process.env["MONGODB_URI_LOCAL"];