NodeJS-client for Spring Cloud Config Server
npm i @day1co/spring-cloud-config-client
const { getConfig } = require('@day1co/spring-cloud-config-client');
getConfig({ endpoint, application, profile, label });
getConfigSync({ endpoint, application, profile, label });
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 likeNODE_ENV
orAPP_ENV
.label
(string; default='main') : The name of config-repo's git branch.
You can override them 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.
console.log(config.all);
// {
// database: {
// host: 'localhost',
// port: 3306,
// },
// }
config.getByKey('database.host'); // 'localhost'
You can override configuration value on client system environment variables.
process.env.DATABASE_HOST = 'overridden';
config.getByKey('database.host'); // 'overridden'
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
http://localhost:8888 에 config 서버가 띄워져 있어야 합니다.
startMockServer
함수를 사용하면 Spring Cloud Config Server를 흉내내는 localhost:8888 서버가 열립니다.- response로 받고자 하는 config 값들을 js 확장자나 json 확장자 파일로 준비합니다. (TOBE: yml 지원)
- 해당 파일은 redstone-config-repo에 있는 yml 파일의 구조와 동일해야 합니다.
- 해당 파일의 path를
startMockServer
호출하는 프로젝트 루트 기준으로 제공해줍니다.
$ pwd
/Users/someone/Desktop/my-project
// read file at /Users/someone/Desktop/my-project/config/local.fixture.js
startMockServer(`config/local.fixture.js`);