From 342a0447bddfe191202b7fcadaae45f7f6f41d37 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Thu, 2 Aug 2018 09:28:28 +0100 Subject: [PATCH 1/2] Load environment variables before requiring routes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Code in `route.js` may be looking for environment variables. If the environment variables aren’t loaded beforehand this will cause an exception. I suspect this worked fine before https://github.com/alphagov/govuk-prototype-kit/commit/bbe15e8fa6d7ba75a7c09c0c5c2c0db7a2e55047#diff-78c12f5adc1848d13b1c6f07055d996e, which reordered the first lines in `server.js`. This commit moves the loading of environment variables to before the requiring of any `routes.js` files. --- server.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server.js b/server.js index f00a2884d9..d7b48f4be3 100644 --- a/server.js +++ b/server.js @@ -11,6 +11,9 @@ const nunjucks = require('nunjucks') const session = require('express-session') const cookieParser = require('cookie-parser') +// Environment variables +dotenv.config() + // Local dependencies const config = require('./app/config.js') const documentationRoutes = require('./docs/documentation_routes.js') @@ -39,8 +42,6 @@ if (useV6) { v6App = express() } -dotenv.config() - // Set cookies for use in cookie banner. app.use(cookieParser()) documentationApp.use(cookieParser()) From 39fbe227eedfa4a67d37d07c767e6977815f688a Mon Sep 17 00:00:00 2001 From: Joe Lanman Date: Wed, 15 Aug 2018 12:25:25 +0100 Subject: [PATCH 2/2] CHANGELOG --- CHANGELOG.md | 1 + server.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e37d3f22d5..0fb6c68790 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ New Features: Bug fixes: +- [Fix loading variables from .env](https://github.com/alphagov/govuk-prototype-kit/pull/583) - [Update link from question page template to design system](https://github.com/alphagov/govuk-prototype-kit/pull/575) - [Changed block name to bodyEnd to fix scripts in unbranded template](https://github.com/alphagov/govuk-prototype-kit/pull/580) diff --git a/server.js b/server.js index d7b48f4be3..e037943384 100644 --- a/server.js +++ b/server.js @@ -11,7 +11,7 @@ const nunjucks = require('nunjucks') const session = require('express-session') const cookieParser = require('cookie-parser') -// Environment variables +// Run before other code to make sure variables from .env are available dotenv.config() // Local dependencies