spring-cloud-config-client
/
1.1.1
spring-cloud-config-client 1.1.1
Install from the command line:
Learn more about npm packages
$ npm install @day1co/spring-cloud-config-client@1.1.1
Install via package.json:
"@day1co/spring-cloud-config-client": "1.1.1"
About this version
NodeJS-client for Spring Cloud Config Server
npm i @day1co/spring-cloud-config-client
const { getConfig } = require('@day1co/spring-cloud-config-client');
const { getConfig } = require('@day1co/spring-cloud-config-client');
getConfig({ endpoint, application, profile, label });
const { getConfigSync } = require('@day1co/spring-cloud-config-client');
getConfigSync({ endpoint, application, profile, label });
const client = require('@day1co/spring-cloud-config-client');
const config = client.getConfigSync({
endpoint: 'http://localhost:8888',
application: 'foo',
profile: 'production',
});
-
endpoint
(string; default='http://localhost:8888') : The endpoint of spring cloud config server. -
application
(string; default='application') : The name of client application that you would like to get. -
profile
(string; default='default') : The name of client application's environment likeD1_ENV
orAPP_ENV
. -
label
(string; default='main') : The name of config-repo's git branch.
You can override above arguments by following system environment variables:
-
SPRING_CLOUD_CONFIG_URI
for default endpoint. -
SPRING_CLOUD_CONFIG_NAME
for default application. -
SPRING_CLOUD_CONFIG_PROFILE
for default profile. -
SPRING_CLOUD_CONFIG_LABEL
. for default label.
const client = require('@day1co/spring-cloud-config-client');
const config = client.getConfigSync({
endpoint: 'http://localhost:8888',
application: 'foo',
profile: 'production',
});
console.log(config.all);
{
database: {
host: 'localhost',
port: 3306,
},
}
const client = require('@day1co/spring-cloud-config-client');
const config = client.getConfigSync({
endpoint: 'http://localhost:8888',
application: 'foo',
profile: 'production',
});
console.log(config.getByKey('database.host'));
'localhost';
You can override configuration value on client system environment variables.
const client = require('@day1co/spring-cloud-config-client');
process.env.DATABASE_HOST = 'overridden';
const config = client.getConfigSync({
endpoint: 'http://localhost:8888',
application: 'foo',
profile: 'production',
});
config.getByKey('database.host');
'overridden';
Note that DATABASE_HOST
environment key must
- match the structure of your config file.
- use snake case with capital letters. In this case, for example, your config file would have lines like,
database:
host: 'localhost'
You can use a mock Spring-Cloud-Config-Server on localhost:8888
without running "real" Spring-Cloud-Config server on your local PC.
It is provided for your local/CI environment.
- Prepare a config file in .js or .json extension.
- Note that the config file must have a structure same as your own "real" config files that "real" Spring-Cloud-Config server would read.
Here's an example.
application.yml (real config file)
foo:
bar: 'real'
/Users/me/Desktop/my-project/fake-config.json (fake config file)
{
"foo": {
"bar": "real"
}
}
- Use
startMockServer
function.
- Arguments
-
filePath
(string;) : a relative path of a fake config file
-
$ pwd
/Users/me/Desktop/my-project
const { startMockServer } = require('@day1co/spring-cloud-config-client');
startMockServer(`fake-config.json`);
This repository is based on https://github.com/victorherraiz/cloud-config-client
See also https://docs.spring.io/spring-cloud-config/docs/current/reference/html/#_spring_cloud_config_client