utsushiiro 7 лет назад
Родитель
Сommit
ff4435edfe
2 измененных файлов с 25 добавлено и 1 удалено
  1. 4 1
      src/server/crowi/index.js
  2. 21 0
      src/server/service/config-manager.js

+ 4 - 1
src/server/crowi/index.js

@@ -33,6 +33,7 @@ function Crowi(rootdir) {
   this.cacheDir    = path.join(this.tmpDir, 'cache');
   this.cacheDir    = path.join(this.tmpDir, 'cache');
 
 
   this.config = {};
   this.config = {};
+  this.configManager = null;
   this.searcher = null;
   this.searcher = null;
   this.mailer = {};
   this.mailer = {};
   this.passportService = null;
   this.passportService = null;
@@ -211,7 +212,9 @@ Crowi.prototype.setupConfigManager = async function() {
   const ConfigLoader = require('../service/config-loader');
   const ConfigLoader = require('../service/config-loader');
   const configLoader = new ConfigLoader(this.model('Config'));
   const configLoader = new ConfigLoader(this.model('Config'));
   const config = await configLoader.load();
   const config = await configLoader.load();
-  console.log(config);
+
+  const ConfigManager = require('../service/config-manager');
+  this.configManager = new ConfigManager(config);
 };
 };
 
 
 Crowi.prototype.setupModels = function() {
 Crowi.prototype.setupModels = function() {

+ 21 - 0
src/server/service/config-manager.js

@@ -0,0 +1,21 @@
+class ConfigManager {
+
+  constructor(configObject) {
+    this.configObject = configObject;
+  }
+
+  getConfig(namespace, key) {
+    return this.defaultSearch(namespace, key);
+  }
+
+  defaultSearch(namespace, key) {
+    if (this.configObject['fromDB'][namespace][key] !== undefined) {
+      return this.configObject['fromDB'][namespace][key];
+    }
+    else {
+      return this.configObject['fromEnvVars'][namespace][key];
+    }
+  }
+}
+
+module.exports = ConfigManager;