sou 7 лет назад
Родитель
Сommit
7c1030866e
3 измененных файлов с 20 добавлено и 4 удалено
  1. 18 0
      lib/crowi/index.js
  2. 1 2
      lib/routes/comment.js
  3. 1 2
      lib/routes/page.js

+ 18 - 0
lib/crowi/index.js

@@ -37,6 +37,7 @@ function Crowi(rootdir, env) {
   this.mailer = {};
   this.interceptorManager = {};
   this.passportService = null;
+  this.globalNotificationService = null;
   this.xss = new Xss();
 
   this.tokens = null;
@@ -90,6 +91,8 @@ Crowi.prototype.init = function() {
       return self.setupSlack();
     }).then(function() {
       return self.setupCsrf();
+    }).then(function() {
+      return self.setUpGlobalNotification();
     });
 };
 
@@ -246,6 +249,10 @@ Crowi.prototype.getInterceptorManager = function() {
   return this.interceptorManager;
 };
 
+Crowi.prototype.getGlobalNotificationService = function() {
+  return this.globalNotificationService;
+};
+
 Crowi.prototype.setupPassport = function() {
   const config = this.getConfig();
   const Config = this.model('Config');
@@ -452,4 +459,15 @@ Crowi.prototype.require = function(modulePath) {
   return require(modulePath);
 };
 
+/**
+ * setup Express Routes
+ * !! this must be at last because it includes '/*' route !!
+ */
+Crowi.prototype.setUpGlobalNotification = function() {
+  const globalNotificationService = require('../service/global-notification');
+  if (this.globalNotificationService == null) {
+    this.globalNotificationService = new globalNotificationService(this);
+  }
+};
+
 module.exports = Crowi;

+ 1 - 2
lib/routes/comment.js

@@ -7,8 +7,7 @@ module.exports = function(crowi, app) {
     , User = crowi.model('User')
     , Page = crowi.model('Page')
     , ApiResponse = require('../util/apiResponse')
-    , globalNotification = require('../service/global-notification')
-    , notification = new globalNotification(crowi)
+    , notification = crowi.getGlobalNotificationService()
     , actions = {}
     , api = {};
 

+ 1 - 2
lib/routes/page.js

@@ -16,8 +16,7 @@ module.exports = function(crowi, app) {
     , pagePathUtil = require('../util/pagePathUtil')
     , swig = require('swig-templates')
     , getToday = require('../util/getToday')
-    , globalNotification = require('../service/global-notification')
-    , notification = new globalNotification(crowi)
+    , notification = crowi.getGlobalNotificationService()
 
     , actions = {};