The regexes used to set config.isProduction in both services are invalid, always returning false, no matter what value NODE_ENV is set to in the respective .env file.
I'm happy to open a PR to fix this, but I'd like to discuss the solution before I start. Just fix it separately in both services? Since titus is a monorepo project, it could be nice to have a utils type module that contains reusable functions, but that seems overkill for this bug.
I think my preference would be to fix it in both services, getting rid of the regexes and either:
Being strict about the value - i.e.
const isProduction = config.NODE_ENV === 'production'
Or else be slightly less strict about the value, e.g.
const isProduction = config.NODE_ENV.trim().toLowerCase() === 'production'
I prefer option # 1, since I'm pretty sure envSchema trims any whitespace from environment variables, anyway.
An in-between option (# 3) would be to expect whitespace to be correct, but use toLowerCase to be less strict about the capitalization.
I've opened the PR with the fix, following your suggestion about being strict about the value.
Also, I've opened an issue (#1483) where we can discuss the creation of a utils (or something alike) module.
The regexes used to set
config.isProduction
in both services are invalid, always returningfalse
, no matter what valueNODE_ENV
is set to in the respective.env
file.Here's the back end code:
https://github.com/nearform/titus/blob/71723b21dacdbd2229f5d6cd0cb10b0924d12e70/packages/titus-backend/lib/config/index.js#L54
And the database manager code:
https://github.com/nearform/titus/blob/743c044c8d7151e098af174f886c8ede141114f6/packages/titus-db-manager/lib/config.js#L22
I'm happy to open a PR to fix this, but I'd like to discuss the solution before I start. Just fix it separately in both services? Since titus is a monorepo project, it could be nice to have a
utils
type module that contains reusable functions, but that seems overkill for this bug.I think my preference would be to fix it in both services, getting rid of the regexes and either:
Being strict about the value - i.e.
const isProduction = config.NODE_ENV === 'production'
Or else be slightly less strict about the value, e.g.
const isProduction = config.NODE_ENV.trim().toLowerCase() === 'production'
I prefer option # 1, since I'm pretty sure
envSchema
trims any whitespace from environment variables, anyway.An in-between option (# 3) would be to expect whitespace to be correct, but use
toLowerCase
to be less strict about the capitalization.