@oerlikon/config
Easily add server and client configuration to your oerlikon app. This package will provide server and client config that can be changed at runtime with environment variables.
Last updated 6 months ago by oerlikon-admin .
ISC · Original npm · Tarball · package.json
$ cnpm install @oerlikon/config 
SYNC missed versions from official npm registry.

@oerlikon/config

Easily add server and client configuration to your oerlikon app. This package will provide server and client config that can be changed at runtime with environment variables.

If you use typescript, you will get typings based on your configuration.

Only the configuration under client will be accessibly on the frontend so your secrets stay secret.

Installation

  1. Install the npm package: npm install @oerlikon/config

  2. Create a JSON config file at ./config/default.json, e.g.

    {
      "serverSecret": "your-secret",
      "client": {
        "apiUrl": "your-url"
      }
    }
    

    This is your default configuration for your app

  3. Add the middleware to your express server:

    import configMiddleware from '@oerlikon/config/middleware';
    
    ...
    
    app.use(configMiddleware);
    
  4. only applies if you use typescript: add typescript include directory: in ./tsconfig.json, add 'config' to include in ./client/tsconfig.json, add '../config' to include

Usage

On the server:

import config from '@oerlikon/config';

console.log(config.serverSecret);

On the client:

import config from '@oerlikon/config/client';

console.log(config.apiUrl);

Advanced usage

set context config

You can place additional config files next to your default.json file:

  • development.json: Config used in development
  • production.json: Config used in production
  • test.json: Config used in testing

All config files will extend the default.json.

overwrite config with environment variables

Place a configuration file name custom-environment-variables.json next to your default.json. It should have the same structure as your other configuration files, but instead of providing values, you provide a mapping between environment variables and your config:

{
  "serverSecret": "SERVER_SECRET",
  "client": {
    "apiUrl": "API_URL"
  }
}

Current Tags

  • 1.0.0-alpha.10                                ...           latest (6 months ago)

4 Versions

  • 1.0.0-alpha.10                                ...           6 months ago
  • 1.0.0-alpha.9                                ...           6 months ago
  • 1.0.0-alpha.8                                ...           6 months ago
  • 1.0.0-alpha.7                                ...           6 months ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (2)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |