- the project obtains the configuration items through the configuration file before it wants to go to devops,. Now it pulls the configuration items from the configuration center, modifies the previous configuration file Synchronize load to obtain the configuration items in etcd through the API, and finds that the asynchronously obtained results cannot be exported?
the code is as follows:
-sharp
var baseConfigFilePath = "../base-config.yaml"; //
var customConfigFilePathEnv = "CONFIG_PATH"; //
var loadFile = exports.loadFile = function loadFile() {
var baseConfigFileFullPath = path.join(__dirname, baseConfigFilePath);
var customConfigFilePath = process.env[customConfigFilePathEnv];
var fileData, obj;
/* */
fileData = fs.readFileSync(baseConfigFileFullPath);
obj = yaml.load(fileData);
//
if (!toolkit.isNullOrWhiteSpace(customConfigFilePath)) {
var customFileData = fs.readFileSync(customConfigFilePath);
var customObj = yaml.load(customFileData);
//
toolkit.objUpdate(customObj, obj);
}
exports.CONFIG = obj;
};
loadFile();
modified
var loadFile = exports.loadFile = function loadFile() {
var baseConfigFileFullPath = path.join(__dirname, baseConfigFilePath);
var customConfigFilePath = process.env[customConfigFilePathEnv];
var fileData, obj;
/* */
fileData = fs.readFileSync(baseConfigFileFullPath);
obj = yaml.load(fileData);
//
if (!toolkit.isNullOrWhiteSpace(customConfigFilePath)) {
// var customFileData = fs.readFileSync(customConfigFilePath);
// var customObj = yaml.load(customFileData);
request(customConfigFilePath, function(error, response, data) {
if (error) {
console.log("", colors.red(""));
}
var resData = JSON.parse(data);
if (resData.errorCode) {
console.log("", colors.red(""));
}
var customObj = toolkit.fromBase64(resData.node.value);
toolkit.objUpdate(customObj, obj);
})
}
exports.CONFIG = obj;
};
exports is handled by Synchronize. The data obtained by etcd cannot be exported. How to deal with this problem while keeping the logic of the source code unchanged?