Code Monkey home page Code Monkey logo

spring-cloud-config-client's Introduction

spring-cloud-config-client

NodeJS-client for Spring Cloud Config Server

version

Getting Started

npm i @day1co/spring-cloud-config-client
const { getConfig } = require('@day1co/spring-cloud-config-client');

How to get config from Spring Cloud server

Asynchronous(preferred)

getConfig({ endpoint, application, profile, label });

Synchronous

getConfigSync({ endpoint, application, profile, label });

Example

const config = client.getConfigSync({
  endpoint: 'http://localhost:8888',
  application: 'foo',
  profile: 'production',
});

Arguments

  • 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 like NODE_ENV or APP_ENV.
  • label (string; default='main') : The name of config-repo's git branch.

System Environments

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.

Getting config as nested object

console.log(config.all);
// {
//   database: {
//     host: 'localhost',
//     port: 3306,
//   },
// }

Getting config by its key

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'

Reference

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 서버가 띄워져 있어야 합니다.

방법1. 모듈 내 embedded-server를 사용한다.

  • 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`);

spring-cloud-config-client's People

Contributors

moonimooni avatar jo-seongjun avatar iolo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.