mizozobu 6 лет назад
Родитель
Сommit
b640c4da03
3 измененных файлов с 48 добавлено и 22 удалено
  1. 12 0
      src/server/crowi/index.js
  2. 0 22
      src/server/service/config-manager.js
  3. 36 0
      src/server/service/site-url.js

+ 12 - 0
src/server/crowi/index.js

@@ -41,6 +41,7 @@ function Crowi(rootdir) {
   this.crowiSlackNotificationService = null;
   this.xssService = null;
   this.aclService = null;
+  this.siteUrlService = null;
   this.restQiitaAPIService = null;
   this.cdnResourcesService = new CdnResourcesService();
   this.interceptorManager = new InterceptorManager();
@@ -89,6 +90,7 @@ Crowi.prototype.init = async function() {
     this.setUpCrowiSlacklNotification(),
     this.setUpXss(),
     this.setUpAcl(),
+    this.setUpSiteUrl(),
     this.setUpRestQiitaAPI(),
   ]);
 };
@@ -474,6 +476,16 @@ Crowi.prototype.setUpAcl = function() {
   }
 };
 
+/**
+ * setup SiteUrlService
+ */
+Crowi.prototype.setUpSiteUrl = function() {
+  const SiteUrlService = require('../service/site-url');
+  if (this.siteUrlService == null) {
+    this.siteUrlService = new SiteUrlService(this);
+  }
+};
+
 /**
  * setup RestQiitaAPIService
  */

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

@@ -1,5 +1,4 @@
 const debug = require('debug')('growi:service:ConfigManager');
-const pathUtils = require('growi-commons').pathUtils;
 const ConfigLoader = require('../service/config-loader');
 
 const KEYS_FOR_SAML_USE_ONLY_ENV_OPTION = [
@@ -71,27 +70,6 @@ class ConfigManager {
     return this.searchOnlyFromEnvVarConfigs(namespace, key);
   }
 
-  /**
-   * get the site url
-   *
-   * If the config for the site url is not set, this returns a message "[The site URL is not set. Please set it!]".
-   *
-   * With version 3.2.3 and below, there is no config for the site URL, so the system always uses auto-generated site URL.
-   * With version 3.2.4 to 3.3.4, the system uses the auto-generated site URL only if the config is not set.
-   * With version 3.3.5 and above, the system use only a value from the config.
-   */
-  /* eslint-disable no-else-return */
-  getSiteUrl() {
-    const siteUrl = this.getConfig('crowi', 'app:siteUrl');
-    if (siteUrl != null) {
-      return pathUtils.removeTrailingSlash(siteUrl);
-    }
-    else {
-      return '[The site URL is not set. Please set it!]';
-    }
-  }
-  /* eslint-enable no-else-return */
-
   // CONF.RF refactor file-uploader
   // create parent class and each uploader inherits from it.
   getIsUploadable() {

+ 36 - 0
src/server/service/site-url.js

@@ -0,0 +1,36 @@
+const logger = require('@alias/logger')('growi:service:SiteUrl'); // eslint-disable-line no-unused-vars
+const { pathUtils } = require('growi-commons');
+
+/**
+ * the service class of GlobalNotificationSetting
+ */
+class SiteUrl {
+
+  constructor(crowi) {
+    this.crowi = crowi;
+  }
+
+  /**
+   * get the site url
+   *
+   * If the config for the site url is not set, this returns a message "[The site URL is not set. Please set it!]".
+   *
+   * With version 3.2.3 and below, there is no config for the site URL, so the system always uses auto-generated site URL.
+   * With version 3.2.4 to 3.3.4, the system uses the auto-generated site URL only if the config is not set.
+   * With version 3.3.5 and above, the system use only a value from the config.
+   */
+  /* eslint-disable no-else-return */
+  getSiteUrl() {
+    const siteUrl = this.getConfig('crowi', 'app:siteUrl');
+    if (siteUrl != null) {
+      return pathUtils.removeTrailingSlash(siteUrl);
+    }
+    else {
+      return '[The site URL is not set. Please set it!]';
+    }
+  }
+  /* eslint-enable no-else-return */
+
+}
+
+module.exports = SiteUrl;