@vidaxl/config-getter-for-microservices

We needed a way to categorize the configuration values to be able to distinguish between them.

Usage no npm install needed!

<script type="module">
  import vidaxlConfigGetterForMicroservices from 'https://cdn.skypack.dev/@vidaxl/config-getter-for-microservices';
</script>

README

Configuration getter for some already existing Vidaxl apis

Motivation

We needed a way to categorize the configuration values to be able to distinguish between them.

See below how we did it.

old configuration:

{
  "couchbaseServiceUrl": "http://couchbase-service:3000/v1/couchbase",
  "productCatalogServiceUrl": "http://product-catalog-service:3000/v1/product-catalog",
  "apmServerUrl": "http://10.51.62.67:8200/"
}

new configuration:

{
  "couchbaseServiceUrl": {
    "value": "http://couchbase-service:3000/v1/couchbase",
    "type": "microservice"
  },
  "productCatalogServiceUrl": {
    "value": "http://product-catalog-service:3000/v1/product-catalog",
    "type": "microservice"
  },
  "apmServerUrl": {
    "value": "http://10.51.62.67:8200/",
    "type": "amp"
  }
}

implementing it

I think you see how it goes, it was needed so we can parse out information for the status-aggregator-vidaxl-config-bridge (also part of this monorepo). I tried to make it compatible with the original system in the src/.../helper/config.js:

module.exports = function config() {
    return {
        getConfig: function(field) {
            return server.environment[field];
        }
    };
};

It implemenets the getConfig function, so this library as well, and with the new structure it works compatible. of course value can be any object. Currently the same file mentioned above looks like:

module.exports = require('@vidaxl/config-getter-for-microservices')(server.environment)

It is prepared for better times as the configuration is injectable, and let's hope we willn not always rely on global values, but it works now perfectly.

If you are implementing this library, please make sure that you copy/overwrite the .npmrc file with the one you find in the MICRO-49 branch of the product-catalog-service soon it will be in the master too.

Important

If you are about to update the src/.../helper/config.js of it's kind and implement this library, please make sure that the file does not implements other functions/methods, if so please refactor the code that those functionalities would be the part of another module.

For more details please consult the test.js