README.md 1.9 KB
Newer Older
Q
Quinton.Xu 已提交
1 2 3 4 5 6 7 8 9 10
[![NPM version][npm-image]][npm-url]
[![David deps][david-image]][david-url]
[![npm download][download-image]][download-url]

[npm-image]: https://img.shields.io/npm/v/node-apollo.svg?style=flat-square
[npm-url]: https://npmjs.org/package/node-apollo
[david-image]: https://img.shields.io/david/Quinton/node-apollo.svg?style=flat-square
[david-url]: https://david-dm.org/Quinton/node-apollo/repo.svg
[download-image]: https://img.shields.io/npm/dm/node-apollo.svg?style=flat-square
[download-url]: https://npmjs.org/package/node-apollo
Q
Quinton.Xu 已提交
11 12 13 14 15 16 17
# node-apollo

  携程Apollo配置中心node SDK.

## Install

```bash
Q
Quinton.Xu 已提交
18
$ npm i node-apollo --save-dev
Q
Quinton.Xu 已提交
19
```
Q
Quinton.Xu 已提交
20 21 22 23 24 25
Node.js >= 6.0.0 required.

## Features

- ✔︎ 适用eggjs, thinkjs等docker部署项目
- ✔︎ 适用自己手动搭建的服务,可直接读取JSON格式的配置
Q
Quinton.Xu 已提交
26 27 28

## Usage

Q
Quinton.Xu 已提交
29
* See [examples](https://github.com/Quinton/node-apollo/tree/master/example)
Q
Quinton.Xu 已提交
30

Q
Quinton.Xu 已提交
31 32 33
## Method

### remoteConfigService
Q
Quinton.Xu 已提交
34 35 36 37 38 39 40 41 42 43
```
  const config = {
      configServerUrl: 'http://example.com',
      appId: '<appId>',
      clusterName: 'default',
      namespaceName: '',
      apolloEnv: 'dev',
      token: '<apollo access token>'
      // clientIp: '',
    };
Q
fix  
Quinton.Xu 已提交
44
  const result = await apollo.remoteConfigService(config);
Q
Quinton.Xu 已提交
45 46
```
  >**NOTE:** 读取携程Apollo配置,调用第三方应用接入Apollo开放平台, 详情请参考[Apollo开放平台](https://github.com/ctripcorp/apollo/wiki/Apollo%E5%BC%80%E6%94%BE%E5%B9%B3%E5%8F%B0).
Q
Quinton.Xu 已提交
47
### createEnvFile
Q
Quinton.Xu 已提交
48 49 50 51 52 53 54 55
```
  const obj = {
      mongoose: 'mongo://127.0.0.1:27017',
      appId: '<appId>',
    };
  apollo.createEnvFile(eggConfig);
```
>**NOTE:** 生成环境变量文件,常用于docker化项目,详细请参考[example](https://github.com/Quinton/node-apollo/tree/master/example).
Q
Quinton.Xu 已提交
56
### setEnv
Q
Quinton.Xu 已提交
57 58 59 60
```
apollo.setEnv();
```
>**NOTE:** 注入环境变量到process.env, 详情亲参考[dotenv](https://github.com/motdotla/dotenv#usage).
Q
Quinton.Xu 已提交
61 62 63 64 65

## TODO
  
 - [] 支持局部配置热更新

Q
Quinton.Xu 已提交
66 67
## License

Q
Quinton.Xu 已提交
68
[MIT](LICENSE)