Просмотр исходного кода

fix #92 初回アクセス時に「TypeError: Cannot read property 'buildIndex' of null」が出力されます

Yuki Takei 8 лет назад
Родитель
Сommit
76f32a7424
1 измененных файлов с 11 добавлено и 8 удалено
  1. 11 8
      lib/util/middlewares.js

+ 11 - 8
lib/util/middlewares.js

@@ -261,15 +261,18 @@ exports.applicationNotInstalled = function() {
 
 exports.checkSearchIndicesGenerated = function(crowi, app) {
   return function(req, res, next) {
-    // build index
     const searcher = crowi.getSearcher();
-    searcher.buildIndex()
-      .then((data) => {
-        if (!data.errors) {
-          debug('Index created.');
-        }
-        return searcher.addAllPages();
-      });
+
+    // build index
+    if (searcher) {
+      searcher.buildIndex()
+        .then((data) => {
+          if (!data.errors) {
+            debug('Index created.');
+          }
+          return searcher.addAllPages();
+        });
+    }
 
     return next();
   };