Explorar el Código

add checkSearchIndicesGenerated to middlewares

Yuki Takei hace 8 años
padre
commit
bf01f1ccbb
Se han modificado 2 ficheros con 17 adiciones y 1 borrados
  1. 1 1
      lib/routes/index.js
  2. 16 0
      lib/util/middlewares.js

+ 1 - 1
lib/routes/index.js

@@ -22,7 +22,7 @@ module.exports = function(crowi, app) {
 
   app.get('/'                        , middleware.applicationInstalled(), loginRequired(crowi, app, false) , page.pageListShow);
 
-  app.get('/installer'               , middleware.applicationNotInstalled() , installer.index);
+  app.get('/installer'               , middleware.applicationNotInstalled() , middleware.checkSearchIndicesGenerated(crowi, app) , installer.index);
   app.post('/installer/createAdmin'  , middleware.applicationNotInstalled() , form.register , csrf, installer.createAdmin);
   //app.post('/installer/user'         , middleware.applicationNotInstalled() , installer.createFirstUser);
 

+ 16 - 0
lib/util/middlewares.js

@@ -260,6 +260,22 @@ 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();
+      });
+
+    return next();
+  };
+}
+
 exports.applicationInstalled = function() {
   return function(req, res, next) {
     var config = req.config;