1.0.0-alpha.6 • Published 4 years ago

oerlikon-app-config v1.0.0-alpha.6

Weekly downloads
4
License
ISC
Repository
-
Last release
4 years ago

oerlikon-app-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-app-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-app-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-app-config';

console.log(config.serverSecret);

On the client:

import config from 'oerlikon-app-config/client';

console.log(config.apiUrl);

Advanced usage

set context config

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

  • development.yml: Config used in development
  • production.yml: Config used in production
  • test.yml: 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"
  }
}
1.0.0-alpha.6

4 years ago

1.0.0-alpha.5

4 years ago

1.0.0-alpha.4

4 years ago

1.0.0-alpha.3

4 years ago

1.0.0-alpha.0

4 years ago