fetch-cloud-config
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

fetch-cloud-config

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'
//     data: ['one', 'two'],
//     greeting: 'hello bob'
//   }
// }
console.log(flat)
// {
//   app.name: 'sample-app'
//   app.api-url: 'https://staging.your.app/api'
//   app.data[0]: 'one'
//   app.data[1]: 'two'
//   app.greeting: 'hello bob'
// }

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

const { raw } = await load(configuration);

In progress

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

Dependents (0)

Package Sidebar

Install

npm i fetch-cloud-config

Weekly Downloads

1

Version

1.1.0

License

MIT

Unpacked Size

34.4 kB

Total Files

7

Last publish

Collaborators

  • marius.kaa