UNPKG

whale-nest-nacos

Version:

If you are a nest micro service architecture, you can use the SDK, so as to realize service discovery based on nacos, distributed load balancing strategy

21 lines 1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getNacosConfig = void 0; const getNacosConfig = (key) => { const nacosConfigString = process.env.NACOS_CONFIG; if (!nacosConfigString) { throw new Error('环境变量 process.env.NACOS_CONFIG 不存在!'); } let nacosConfig = JSON.parse(nacosConfigString); const { client_conf, server_conf_list } = nacosConfig || {}; let serverAddress = (server_conf_list || []).map(({ IpAddr, Port }) => `${IpAddr}:${Port}`); const nacosInfo = { serverAddress: serverAddress[0], namespace: client_conf === null || client_conf === void 0 ? void 0 : client_conf.NamespaceId, username: client_conf === null || client_conf === void 0 ? void 0 : client_conf.Username, password: client_conf === null || client_conf === void 0 ? void 0 : client_conf.Password }; return nacosInfo[key]; }; exports.getNacosConfig = getNacosConfig; //# sourceMappingURL=utils.js.map