npm.io
1.0.14 • Published 1 year ago

@jswork/hot-config-service

Licence
MIT
Version
1.0.14
Deps
3
Size
77 kB
Vulns
3
Weekly
0

hot-config-service

A lightweight JavaScript class for dynamic configurations.

version license size download

installation

yarn add @jswork/hot-config-service

usage

import HotConfigService from '@jswork/hot-config-service';

const hotConfig = new HotConfigService({
  // 环境配置,可以设置多个环境的API地址
  envs: {
    'beta': 'https://student-api.beta.saybot.net',
    'production': 'https://student-api.alo7.com'
  },
  // 当前环境
  env: 'beta',
  // API路径,可选,默认为空
  path: '/api/v2/configurations/',
  // 请求超时时间,可选,默认为30秒
  timeout: 30000,
  // 当请求失败时的默认配置,可选
  fallback: {}
});

// 获取配置
await hotConfig.fetch();

// 获取整个配置对象
const config = hotConfig.get();

// 获取特定路径的配置值
const value = hotConfig.get('some.nested.key');

license

Code released under the MIT license.

Keywords