From 20949020d28769594d1849cd3ae5231539f70146 Mon Sep 17 00:00:00 2001 From: Rafi Date: Sun, 19 Jan 2020 10:58:39 -0800 Subject: [PATCH] Fixes #396: add default values to environment variables --- src/backend/lib/config.js | 11 ++++++++++- src/backend/utils/wiki-feed-parser.js | 13 +++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/backend/lib/config.js b/src/backend/lib/config.js index 4ca624acf4..5f35bf1b46 100644 --- a/src/backend/lib/config.js +++ b/src/backend/lib/config.js @@ -1,3 +1,12 @@ const dotenv = require('dotenv'); +const { logger } = require('../utils/logger'); -dotenv.config(); +const result = dotenv.config(); + +if (result.error && logger) { + logger.error( + '\n\n\t💡 It appears that you have not yet configured a .env file.', + '\n\t Please refer to our documentation regarding environment configuration:', + '\n\t https://github.com/Seneca-CDOT/telescope/blob/master/docs/CONTRIBUTING.md\n' + ); +} diff --git a/src/backend/utils/wiki-feed-parser.js b/src/backend/utils/wiki-feed-parser.js index 73d1627f08..f9b52a2009 100644 --- a/src/backend/utils/wiki-feed-parser.js +++ b/src/backend/utils/wiki-feed-parser.js @@ -14,7 +14,7 @@ const { JSDOM } = jsdom; */ async function getWikiText(url) { try { - const response = await fetch(process.env.FEED_URL); + const response = await fetch(url); const data = await response.text(); const dom = new JSDOM(data); @@ -35,9 +35,14 @@ async function getWikiText(url) { * url: "feed url of user" * } */ -module.exports = async function() { - // NOTE: we expect this URL to the CDOT wiki feed list to exist in .env - const url = process.env.FEED_URL; +module.exports = async function () { + let url = process.env.FEED_URL; + + if (!url) { + url = 'https://wiki.cdot.senecacollege.ca/wiki/Planet_CDOT_Feed_List'; + logger.debug(`No value found for FEED_URL in env, using default ${url} instead`); + } + const nameCheck = /^\s*name/i; const commentCheck = /^\s*#/;