Yuki Takei 7 лет назад
Родитель
Сommit
9f31bc0f89

+ 36 - 0
src/server/routes/apiv3/healthcheck.js

@@ -0,0 +1,36 @@
+const loggerFactory = require('@alias/logger');
+const logger = loggerFactory('growi:routes:apiv3:healthcheck');   // eslint-disable-line no-unused-vars
+
+const express = require('express');
+const router = express.Router();
+
+const helmet = require('helmet');
+
+module.exports = (crowi) => {
+
+  router.get('/', helmet.noCache(), async function(req, res) {
+    const connectToMiddlewares = req.query.connectToMiddlewares;
+
+    // return 200 w/o connecting to MongoDB and Elasticsearch
+    if (connectToMiddlewares == null) {
+      res.status(200).send({ status: 'OK' });
+      return;
+    }
+
+    try {
+      // connect to MongoDB
+      const Config = crowi.models.Config;
+      await Config.findOne({});
+      // connect to Elasticsearch
+      const search = crowi.getSearcher();
+      const esInfo = await search.getInfo();
+
+      res.status(200).send({ mongo: 'OK', esInfo });
+    }
+    catch (err) {
+      res.status(503).send({err});
+    }
+  });
+
+  return router;
+};

+ 10 - 0
src/server/routes/apiv3/index.js

@@ -0,0 +1,10 @@
+const loggerFactory = require('@alias/logger');
+const logger = loggerFactory('growi:routes:apiv3');   // eslint-disable-line no-unused-vars
+
+const express = require('express');
+const router = express.Router();
+
+module.exports = (crowi) => {
+  router.use('/healthcheck', require('./healthcheck')(crowi));
+  return router;
+};

+ 3 - 10
src/server/routes/index.js

@@ -211,16 +211,6 @@ module.exports = function(crowi, app) {
   app.get( '/_api/revisions.ids'      , accessTokenParser , loginRequired(crowi, app, false) , revision.api.ids);
   app.get( '/_api/revisions.ids'      , accessTokenParser , loginRequired(crowi, app, false) , revision.api.ids);
   app.get( '/_api/revisions.list'     , accessTokenParser , loginRequired(crowi, app, false) , revision.api.list);
   app.get( '/_api/revisions.list'     , accessTokenParser , loginRequired(crowi, app, false) , revision.api.list);
 
 
-  //app.get('/_api/revision/:id'     , user.useUserData()         , revision.api.get);
-  //app.get('/_api/r/:revisionId'    , user.useUserData()         , page.api.get);
-
-  /*
-   * WIP: removing pageEdit action
-   * see https://weseek.myjetbrains.com/youtrack/issue/GC-610
-   *
-  app.post('/_/edit'                 , form.revision             , loginRequired(crowi, app) , csrf, page.pageEdit);
-  */
-
   app.get('/trash$'                  , loginRequired(crowi, app, false) , page.trashPageShowWrapper);
   app.get('/trash$'                  , loginRequired(crowi, app, false) , page.trashPageShowWrapper);
   app.get('/trash/$'                 , loginRequired(crowi, app, false) , page.trashPageListShowWrapper);
   app.get('/trash/$'                 , loginRequired(crowi, app, false) , page.trashPageListShowWrapper);
   app.get('/trash/*/$'               , loginRequired(crowi, app, false) , page.deletedPageListShowWrapper);
   app.get('/trash/*/$'               , loginRequired(crowi, app, false) , page.deletedPageListShowWrapper);
@@ -230,6 +220,9 @@ module.exports = function(crowi, app) {
   app.post('/_api/hackmd.integrate'    , accessTokenParser , loginRequired(crowi, app) , csrf, hackmd.validateForApi, hackmd.integrate);
   app.post('/_api/hackmd.integrate'    , accessTokenParser , loginRequired(crowi, app) , csrf, hackmd.validateForApi, hackmd.integrate);
   app.post('/_api/hackmd.saveOnHackmd' , accessTokenParser , loginRequired(crowi, app) , csrf, hackmd.validateForApi, hackmd.saveOnHackmd);
   app.post('/_api/hackmd.saveOnHackmd' , accessTokenParser , loginRequired(crowi, app) , csrf, hackmd.validateForApi, hackmd.saveOnHackmd);
 
 
+  // API v3
+  app.use('/_api/v3', require('./apiv3')(crowi));
+
   app.get('/*/$'                   , loginRequired(crowi, app, false) , page.pageListShowWrapper);
   app.get('/*/$'                   , loginRequired(crowi, app, false) , page.pageListShowWrapper);
   app.get('/*'                     , loginRequired(crowi, app, false) , page.pageShowWrapper);
   app.get('/*'                     , loginRequired(crowi, app, false) , page.pageShowWrapper);
 };
 };

+ 3 - 3
src/server/util/search.js

@@ -27,12 +27,12 @@ function SearchClient(crowi, esUri) {
   this.mappingFile = crowi.resourceDir + 'search/mappings.json';
   this.mappingFile = crowi.resourceDir + 'search/mappings.json';
 }
 }
 
 
-SearchClient.prototype.checkESVersion = function() {
-  // TODO
+SearchClient.prototype.getInfo = function() {
+  return this.client.info({});
 };
 };
 
 
 SearchClient.prototype.registerUpdateEvent = function() {
 SearchClient.prototype.registerUpdateEvent = function() {
-  var pageEvent = this.crowi.event('page');
+  const pageEvent = this.crowi.event('page');
   pageEvent.on('create', this.syncPageCreated.bind(this));
   pageEvent.on('create', this.syncPageCreated.bind(this));
   pageEvent.on('update', this.syncPageUpdated.bind(this));
   pageEvent.on('update', this.syncPageUpdated.bind(this));
   pageEvent.on('delete', this.syncPageDeleted.bind(this));
   pageEvent.on('delete', this.syncPageDeleted.bind(this));