hapijs / glue

Server composer for hapi.js
Other
245 stars 62 forks source link

Parsing $env from manifest JSON outside of server config #10

Closed dstevensio closed 9 years ago

dstevensio commented 9 years ago

I had occasion to pass environment variables in to my application via the manifest file, and wanted to do so in the same manner that you can specify the server port as $env.port for instance. I achieved this by specifying the environment variables as strings in the JSON file like $env.MY_CUSTOM_KEY and then after require-ing the JSON file to create the manifest object, I looped over the area I had specified these values and pulled in the actual values using process.env() like so:

  if (manifest.server.app.config) {
    var value;
    Object.keys(manifest.server.app.config).forEach(function (conf) {
      value = manifest.server.app.config[conf];
      if (value.indexOf('$env') !== -1) {
        manifest.server.app.config[conf] = process.env[value.replace('$env.','')];
      }
    });
  }

I'd like to propose having this functionality built in (implemented in a better fashion, naturally) but I'm not sure whether this should happen in Glue (because of the relevance of the manifest file to Glue) or in hapi itself (because the processing that pulls out the $env for port etc happens there).

Could someone provide guidance on this? Or kill the whole idea for a reason I'm not thinking of?

I'll fork and PR once I know the preferred location for this functionality, if any.

Thanks

csrl commented 9 years ago

Rejoice implements environment variable parsing.

https://github.com/hapijs/rejoice/blob/master/lib/index.js#L111

Glue does not deal with the process/environment.

lock[bot] commented 4 years ago

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.