Skip to content
This repository has been archived by the owner on Apr 20, 2019. It is now read-only.

JSON Environment Variables #49

Closed
cschnaith opened this issue Jan 6, 2016 · 2 comments
Closed

JSON Environment Variables #49

cschnaith opened this issue Jan 6, 2016 · 2 comments

Comments

@cschnaith
Copy link

I would like my configuration file to reference JSON environment variables. I don’t believe Rejoice can handle this:

"plugins": { "dbModule": "$env.jsonEnvVariable" }

where jsonEnvVariable is a list of db connection details as such:

[{"options":{"name":"db1", ... }}
,{"options":{"name":"db2", ...}}]

Rejoice passes this environment variable one time into the dbModule register function as a string (as expected). I would like it to call the dbModule register function twice, once for each option object (how it behaves if the JSON is hardcoded). This would allow me to continue leveraging the simplicity of Rejoice for configuration setup rather than handling this in the dbModule.

My suggestion for a fix:

Rejoice's parseEnv function (line 110) could check if

process.env[value.slice(5)]

returns valid JSON, and if so,

JSON.parse the key value rather than keep it a string.

Something like this:

try{
        manifest[key] = JSON.parse(process.env[value.slice(5)]);
    }

catch(e){
                manifest[key] = process.env[value.slice(5)];
            }
@lloydbenson
Copy link
Contributor

This sounds like it could be useful. I checked with a few members to make sure this doesn't go out of scope of its intended purpose and I think this is a reasonable change. Feel free to do a PR to add this feature and add the required test(s) to ensure it is fully covered. Thanks in advance!

@lloydbenson
Copy link
Contributor

Closing this issue up due to lack of activity.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants