Work on copy config if needed.

This commit is contained in:
Scott Idem
2022-05-06 16:56:12 -04:00
parent 31b278f238
commit 7b4f39760c
3 changed files with 24 additions and 7 deletions

View File

@@ -24,6 +24,9 @@ exports.load_config = function () {
console.log(`CWD: ${cwd}`);
try {
if (cwd == '/') {
cwd = '[home]';
}
console.log('Reading directory...');
let directory_list = fs_promises.readdir(cwd).then(function (read_dir_result) {
console.log('Got contents:');
@@ -81,18 +84,24 @@ exports.load_config = function () {
// config = JSON.parse(fs.readFileSync(config_path));
// console.log('Config file read.');
} else if (fs.existsSync('config.json')) {
} else if (fs.existsSync(path.join(cwd, 'config.json'))) {
//fs.copyFileSync(default_config_path, config_path);
//console.log('Default config file copied: '+config_directory);
console.log(`Config file (config.json) not found under ${config_directory}. Using config in CWD. ${process.cwd()}`);
config_path = 'config.json';
console.log(`Config file (config.json) not found under ${config_directory}. Using config in CWD. ${cwd}`);
config_path = path.join(cwd, 'config.json');
// config = JSON.parse(fs.readFileSync('config.json'));
// console.log('Config file read.');
console.log(`Config file (config.json) not found under ${config_directory}. Using config in CWD. ${cwd}`);
found_config_path = path.join(cwd, 'config.json');
//console.log('Config file (config.json) not found under '+config_directory+'. Using config in CWD.');
//config = JSON.parse(fs.readFileSync('config.json'));
fs.copyFileSync(found_config_path, config_path);
console.log(`Found config file copied: ${config_directory}`);
} else if (fs.existsSync(path.join(cwd, 'config.json.default'))) {
console.log(`Config file (config.json) not found under ${config_directory} or CWD. Using default config in CWD. ${cwd}`);
default_config_path = path.join(cwd, 'config.json.default');
fs.copyFileSync(default_config_path, config_path);
console.log(`Default config file copied: ${config_directory}`);
} else {
console.log('Can not find a config file.');
@@ -105,6 +114,10 @@ exports.load_config = function () {
config.home_directory = home_directory; // From the OS platform
config.tmp_directory = tmp_directory; // From the OS platform
config.app_root_path = config.app_root_path.replace('[home]', home_directory);
config.app_root_path = config.app_root_path.replace('[tmp]', tmp_directory);
console.log(config.app_root_path);
config.host_file_cache_path = config.host_file_cache_path.replace('[home]', home_directory);
config.host_file_cache_path = config.host_file_cache_path.replace('[tmp]', tmp_directory);
console.log(config.host_file_cache_path);

View File

@@ -5,6 +5,8 @@
"event_location_id": "7ReVVemiSM0",
"event_session_id": null,
"app_root_path": "[home]/tmp/OSIT/native_app",
"api_secret_key": "dFP6J9DVj9hUgIMn-fNIqg",
"api_remote_base_url": "https://dev-fastapi.oneskyit.com",
"api_local_base_url": "http://dev-fastapi.oneskyit.local:5005",

View File

@@ -9,6 +9,8 @@
"event_location_code": "",
"event_session_id": "",
"app_root_path": "[home]/OSIT/native_app",
"api_secret_key": "ABCD1234XYZ",
"api_server_base_url": "http://dev-api.oneskyit.local:5005",