8000 GitHub - plindberg/figre: Small Node library for 12-factor apps, combines single config from various sources: environment, platform deep JSON config, etc.. This is from a now defunct startup I co-founded, where we ran on IBM BlueMix, which was based on Cloud Foundry. Not maintained, but might be of use to someone.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Small Node library for 12-factor apps, combines single config from various sources: environment, platform deep JSON config, etc.. This is from a now defunct startup I co-founded, where we ran on IBM BlueMix, which was based on Cloud Foundry. Not maintained, but might be of use to someone.

Notifications You must be signed in to change notification settings

plindberg/figre

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

figre

The name comes from ”config resolution” (con-fig re-solution).

Following The Twelve-Factor App, we like to keep the configuration for an app in its environment. Not in files that are checked into Git. Definitely not inline in the code.

To keep things tidy and clear, we want to declaratively map the config to the environment variables, in a single spot, and inject it into the parts of the code that need it.

Some platforms, like Cloud Foundry, has an extended environment, where bound services can be looked up. This package allows mapping your config to that as well.

See this example:

const ConfigResolver = require('figre/resolver'),
  cfenv = require('cfenv').getAppEnv(),
  config = ConfigResolver.create({
    _options: {
      loadEnvFile: cfenv.isLocal
    },
    _context: {
      _cfenv: cfenv
    },
    httpServer: {
      port: {_cfenv: 'port'},
      url: {_cfenv: 'url'}
    },
    auth: {
      transactions: {
        jwtSecret: {_env: 'JWT_SECRET_TRANSACTIONS'}
      }
    },
    logging: {
      level: {_env: 'LOG_LEVEL', _default: 'info'}
    },
    redis: {_env: 'REDIS', _format: 'JSON'}
  });

This would go early in your app.js. It maps the config auth.transactions.jwtSecret to the environment variable JWT_SECRET_TRANSACTIONS. It adds the Cloud Foundry environment and maps the port and URL for the HTTP server. It sets config.logging.level to "info" unless the environment variable LOG_LEVEL exists. Finally, it allows setting any Redis options as JSON in the environment variable REDIS.

About

Small Node library for 12-factor apps, combines single config from various sources: environment, platform deep JSON config, etc.. This is from a now defunct startup I co-founded, where we ran on IBM BlueMix, which was based on Cloud Foundry. Not maintained, but might be of use to someone.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0