govuk-prototype-kit
govuk-prototype-kit copied to clipboard
Access config from users routes.js
Context
I'd like to be able to make my prototype work differently in production than in development. For example I'd like to add logging of the session data, but only do this in development, to aid with debugging, and not do in production (to prevent too many logs and the server falling over).
Alternatives
I'm importing the config directly: const config = require('home-office-govuk-prototype-kit/lib/config')
in my routes.js
file, but aware that this isn't particularly desirable. Then I've got if (config.getConfig().isDevelopment) {}
.
Possible solution
Would it be possible to add the getConfig function to index.js, so that my routes file can call getConfig and then use config.isDevelopment
, or make a configApi - just to be able to read the config.
just a thought - would this particular case be better served by environment variables and the use of .env file? Then you can check process.env
anywhere:
https://nodejs.dev/en/learn/how-to-read-environment-variables-from-nodejs/
I noticed that in the govuk prototype kit it uses the environment variables, except for deployments on glitch as glitch doesn't set the environment variable: https://github.com/alphagov/govuk-prototype-kit/blob/3769c0e99e1dca98d46a74916f79d0f274bceb90/lib/config.js#L54C5-L54C5
It'd be good to just have one way of determining the environment the prototype is running in.