Skip to content

mariuskaa/fetch-cloud-config

Repository files navigation

fetch-cloud-config

npm

Fetch configs from spring-cloud-config servers.

Installation

# using yarn
yarn add fetch-cloud-config

# using npm
npm i fetch-cloud-config

Usage

import { load } from 'spring-cloud-config'

load({
    host: 'http//your-config-server.com',
    profiles: ['staging'],
    name: 'your-app-name'
}).then(({properties}) => {
    console.log(properties)
})

fetch-cloud-config also fully supports typescript. This is demonstrated in the examples below.

Examples

load retrieves and merges property sources as specified in your configuration. One can either use the default nested model, opt for a flattened model, or use raw data from the spring-cloud-config server. Spring environment-variable placeholders can be resolved by adding an 'environment' configuration.

# application.yml
app:
  name: sample-app
  api-url: https://your.app/api
  greeting: hello ${USER}

data:
  - one
  - two
# application-staging.yml
app:
  api-url: https://staging.your.app/api
import { load, Configuration } from 'fetch-cloud-config';

const configuration: Configuration = {
    host: 'https://config.server', 
    name: 'application', 
    profiles: ['staging'],
    environment: { USER: 'bob' }
};

type AppConfig = { app: { name: string, 'api-url': string, data: string[]}}

const { properies, flat } = await load<AppConfig>(configuration);
console.log(properties)
// {
//   app: {
//     name: 'sample-app',
//     api-url: 'https://staging.your.app/api'
//     greeting: 'hello bob'
//   },
//   data: ['one', 'two']
// }
console.log(flat)
// {
//   app.name: 'sample-app'
//   app.api-url: 'https://staging.your.app/api'
//   app.greeting: 'hello bob'
//   data[0]: 'one'
//   data[1]: 'two'
// }

The raw Spring data can also be accessed through the load result:

const { raw } = await load(configuration);

In progress

  • Flattened configuration
  • Authentication
  • Variable expansion (${SOME_ENV_VAR}) using a provided context

About

Fetch configs from spring-cloud-config servers

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published