https://github.com/nodecloud/nodecloud-config-client
A client for spring-cloud-config-server written by node.
https://github.com/nodecloud/nodecloud-config-client
Last synced: about 2 months ago
JSON representation
A client for spring-cloud-config-server written by node.
- Host: GitHub
- URL: https://github.com/nodecloud/nodecloud-config-client
- Owner: nodecloud
- Created: 2017-06-04T04:21:46.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-24T06:47:35.000Z (about 8 years ago)
- Last Synced: 2025-10-14T05:38:34.952Z (3 months ago)
- Language: JavaScript
- Size: 26.4 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# NodeCloud-Config-Client
This is a client for springcloud-config-server written by node.
## Usage
```
npm install nodecloud-config-client --save
```
```javascript
import Client, {CONFIG_REFRESH_EVENT, ERROR_EVENT} from 'nodecloud-config-client';
import path from 'path';
const client = new Client({
remote: {
url: 'http://localhost:8888/:service/:env',
service: 'service',
interval: 60000,
watch: false
},
local: {
path: path.resolve(__dirname),
service: 'service',
ext: 'yml'
}
});
client.on(CONFIG_REFRESH_EVENT, config => {
console.log(config);
});
client.on("web.port", port => {
console.log('The port is ' + port);
});
client.on(ERROR_EVENT, err => {
console.log(err);
});
```
## API
### new ConfigClient(options)
* @param options
* @param options.remote.url (params: {service, env})
* @param options.remote.client Custom http client. It's an object implement send method with promisify.
* @param options.remote.service The name of the service.
* @param options.remote.interval How long to refresh the configuration, default is one minute.(millisecond)
* @param options.remote.watch
* @param options.local.path The position of the local config file.
* @param options.local.service The name of the service.
* @param options.local.ext The file type of the configuration, supports js or yml.
### client.on(eventName, callback)
* CONFIG_REFRESH_EVENT
* ERROR_EVENT
* Your configuration path
### await client.getConfig()
### await client.getConfig(path, defaultValue)
### client.destroy()
## Custom http client
```
import rp from 'request-promise';
const options = {
remote: {
client: {
send(request) {
//compile uri params.
request.url = uriParams(request.url, request.params);
//force setting the config.
request.simple = true;
request.json = true;
request.resolveWithFullResponse = false;
return rp(request);
}
}
}
}
```