index.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. /* eslint-disable @typescript-eslint/no-this-alias */
  2. import http from 'http';
  3. import path from 'path';
  4. import { createTerminus } from '@godaddy/terminus';
  5. import lsxRoutes from '@growi/plugin-lsx/server/routes';
  6. import mongoose from 'mongoose';
  7. import next from 'next';
  8. import pkg from '^/package.json';
  9. import CdnResourcesService from '~/services/cdn-resources-service';
  10. import Xss from '~/services/xss';
  11. import loggerFactory from '~/utils/logger';
  12. import { projectRoot } from '~/utils/project-dir-utils';
  13. import Activity from '../models/activity';
  14. import PageRedirect from '../models/page-redirect';
  15. import Tag from '../models/tag';
  16. import UserGroup from '../models/user-group';
  17. import AclService from '../service/acl';
  18. import AppService from '../service/app';
  19. import AttachmentService from '../service/attachment';
  20. import ConfigManager from '../service/config-manager';
  21. import { InstallerService } from '../service/installer';
  22. import PageService from '../service/page';
  23. import PageGrantService from '../service/page-grant';
  24. import PageOperationService from '../service/page-operation';
  25. import SearchService from '../service/search';
  26. import { SlackIntegrationService } from '../service/slack-integration';
  27. import { UserNotificationService } from '../service/user-notification';
  28. import { initMongooseGlobalSettings, getMongoUri, mongoOptions } from '../util/mongoose-utils';
  29. const logger = loggerFactory('growi:crowi');
  30. const httpErrorHandler = require('../middlewares/http-error-handler');
  31. const models = require('../models');
  32. const sep = path.sep;
  33. function Crowi() {
  34. this.version = pkg.version;
  35. this.runtimeVersions = undefined; // initialized by scanRuntimeVersions()
  36. this.publicDir = path.join(projectRoot, 'public') + sep;
  37. this.resourceDir = path.join(projectRoot, 'resource') + sep;
  38. this.localeDir = path.join(this.resourceDir, 'locales') + sep;
  39. this.viewsDir = path.resolve(__dirname, '../views') + sep;
  40. this.tmpDir = path.join(projectRoot, 'tmp') + sep;
  41. this.cacheDir = path.join(this.tmpDir, 'cache');
  42. this.express = null;
  43. this.config = {};
  44. this.configManager = null;
  45. this.s2sMessagingService = null;
  46. this.mailService = null;
  47. this.passportService = null;
  48. this.globalNotificationService = null;
  49. this.userNotificationService = null;
  50. this.xssService = null;
  51. this.aclService = null;
  52. this.appService = null;
  53. this.fileUploadService = null;
  54. this.restQiitaAPIService = null;
  55. this.growiBridgeService = null;
  56. this.exportService = null;
  57. this.importService = null;
  58. this.searchService = null;
  59. this.socketIoService = null;
  60. this.pageService = null;
  61. this.syncPageStatusService = null;
  62. this.cdnResourcesService = new CdnResourcesService();
  63. this.slackIntegrationService = null;
  64. this.inAppNotificationService = null;
  65. this.activityService = null;
  66. this.commentService = null;
  67. this.xss = new Xss();
  68. this.tokens = null;
  69. this.models = {};
  70. this.env = process.env;
  71. this.node_env = this.env.NODE_ENV || 'development';
  72. this.port = this.env.PORT || 3000;
  73. this.events = {
  74. user: new (require('../events/user'))(this),
  75. page: new (require('../events/page'))(this),
  76. activity: new (require('../events/activity'))(this),
  77. bookmark: new (require('../events/bookmark'))(this),
  78. comment: new (require('../events/comment'))(this),
  79. tag: new (require('../events/tag'))(this),
  80. admin: new (require('../events/admin'))(this),
  81. };
  82. }
  83. Crowi.prototype.init = async function() {
  84. await this.setupDatabase();
  85. await this.setupModels();
  86. await this.setupConfigManager();
  87. await this.setupSessionConfig();
  88. // setup messaging services
  89. await this.setupS2sMessagingService();
  90. await this.setupSocketIoService();
  91. // customizeService depends on AppService and XssService
  92. // passportService depends on appService
  93. // export and import depends on setUpGrowiBridge
  94. await Promise.all([
  95. this.setUpApp(),
  96. this.setUpXss(),
  97. this.setUpGrowiBridge(),
  98. ]);
  99. await Promise.all([
  100. this.scanRuntimeVersions(),
  101. this.setupPassport(),
  102. this.setupSearcher(),
  103. this.setupMailer(),
  104. this.setupSlackIntegrationService(),
  105. this.setUpFileUpload(),
  106. this.setUpFileUploaderSwitchService(),
  107. this.setupAttachmentService(),
  108. this.setUpAcl(),
  109. this.setUpCustomize(),
  110. this.setUpRestQiitaAPI(),
  111. this.setupUserGroupService(),
  112. this.setupExport(),
  113. this.setupImport(),
  114. this.setupPageService(),
  115. this.setupInAppNotificationService(),
  116. this.setupActivityService(),
  117. this.setupCommentService(),
  118. this.setupSyncPageStatusService(),
  119. ]);
  120. // globalNotification depends on slack and mailer
  121. await Promise.all([
  122. this.setUpGlobalNotification(),
  123. this.setUpUserNotification(),
  124. ]);
  125. await this.autoInstall();
  126. };
  127. /**
  128. * Execute functions that should be run after the express server is ready.
  129. */
  130. Crowi.prototype.asyncAfterExpressServerReady = async function() {
  131. if (this.pageOperationService != null) {
  132. await this.pageOperationService.afterExpressServerReady();
  133. }
  134. };
  135. Crowi.prototype.isPageId = function(pageId) {
  136. if (!pageId) {
  137. return false;
  138. }
  139. if (typeof pageId === 'string' && pageId.match(/^[\da-f]{24}$/)) {
  140. return true;
  141. }
  142. return false;
  143. };
  144. Crowi.prototype.setConfig = function(config) {
  145. this.config = config;
  146. };
  147. Crowi.prototype.getConfig = function() {
  148. return this.config;
  149. };
  150. Crowi.prototype.getEnv = function() {
  151. return this.env;
  152. };
  153. // getter/setter of model instance
  154. //
  155. Crowi.prototype.model = function(name, model) {
  156. if (model != null) {
  157. this.models[name] = model;
  158. }
  159. return this.models[name];
  160. };
  161. // getter/setter of event instance
  162. Crowi.prototype.event = function(name, event) {
  163. if (event) {
  164. this.events[name] = event;
  165. }
  166. return this.events[name];
  167. };
  168. Crowi.prototype.setupDatabase = function() {
  169. mongoose.Promise = global.Promise;
  170. // mongoUri = mongodb://user:password@host/dbname
  171. const mongoUri = getMongoUri();
  172. initMongooseGlobalSettings();
  173. return mongoose.connect(mongoUri, mongoOptions);
  174. };
  175. Crowi.prototype.setupSessionConfig = async function() {
  176. const session = require('express-session');
  177. const sessionMaxAge = this.configManager.getConfig('crowi', 'security:sessionMaxAge') || 2592000000; // default: 30days
  178. const redisUrl = this.env.REDISTOGO_URL || this.env.REDIS_URI || this.env.REDIS_URL || null;
  179. const uid = require('uid-safe').sync;
  180. // generate pre-defined uid for healthcheck
  181. const healthcheckUid = uid(24);
  182. const sessionConfig = {
  183. rolling: true,
  184. secret: this.env.SECRET_TOKEN || 'this is default session secret',
  185. resave: false,
  186. saveUninitialized: true,
  187. cookie: {
  188. maxAge: sessionMaxAge,
  189. },
  190. genid(req) {
  191. // return pre-defined uid when healthcheck
  192. if (req.path === '/_api/v3/healthcheck') {
  193. return healthcheckUid;
  194. }
  195. return uid(24);
  196. },
  197. };
  198. if (this.env.SESSION_NAME) {
  199. sessionConfig.name = this.env.SESSION_NAME;
  200. }
  201. // use Redis for session store
  202. if (redisUrl) {
  203. const redis = require('redis');
  204. const redisClient = redis.createClient({ url: redisUrl });
  205. const RedisStore = require('connect-redis')(session);
  206. sessionConfig.store = new RedisStore({ client: redisClient });
  207. }
  208. // use MongoDB for session store
  209. else {
  210. const MongoStore = require('connect-mongo');
  211. sessionConfig.store = MongoStore.create({ client: mongoose.connection.getClient() });
  212. }
  213. this.sessionConfig = sessionConfig;
  214. };
  215. Crowi.prototype.setupConfigManager = async function() {
  216. this.configManager = new ConfigManager();
  217. return this.configManager.loadConfigs();
  218. };
  219. Crowi.prototype.setupS2sMessagingService = async function() {
  220. const s2sMessagingService = require('../service/s2s-messaging')(this);
  221. if (s2sMessagingService != null) {
  222. s2sMessagingService.subscribe();
  223. this.configManager.setS2sMessagingService(s2sMessagingService);
  224. // add as a message handler
  225. s2sMessagingService.addMessageHandler(this.configManager);
  226. this.s2sMessagingService = s2sMessagingService;
  227. }
  228. };
  229. Crowi.prototype.setupSocketIoService = async function() {
  230. const SocketIoService = require('../service/socket-io');
  231. if (this.socketIoService == null) {
  232. this.socketIoService = new SocketIoService(this);
  233. }
  234. };
  235. Crowi.prototype.setupModels = async function() {
  236. let allModels = {};
  237. // include models that dependent on crowi
  238. allModels = models;
  239. // include models that independent from crowi
  240. allModels.Activity = Activity;
  241. allModels.Tag = Tag;
  242. allModels.UserGroup = UserGroup;
  243. allModels.PageRedirect = PageRedirect;
  244. Object.keys(allModels).forEach((key) => {
  245. return this.model(key, models[key](this));
  246. });
  247. };
  248. Crowi.prototype.scanRuntimeVersions = async function() {
  249. const self = this;
  250. const check = require('check-node-version');
  251. return new Promise((resolve, reject) => {
  252. check((err, result) => {
  253. if (err) {
  254. reject(err);
  255. }
  256. self.runtimeVersions = result;
  257. resolve();
  258. });
  259. });
  260. };
  261. Crowi.prototype.getSlack = function() {
  262. return this.slack;
  263. };
  264. Crowi.prototype.getSlackLegacy = function() {
  265. return this.slackLegacy;
  266. };
  267. Crowi.prototype.getGlobalNotificationService = function() {
  268. return this.globalNotificationService;
  269. };
  270. Crowi.prototype.getUserNotificationService = function() {
  271. return this.userNotificationService;
  272. };
  273. Crowi.prototype.getRestQiitaAPIService = function() {
  274. return this.restQiitaAPIService;
  275. };
  276. Crowi.prototype.setupPassport = async function() {
  277. logger.debug('Passport is enabled');
  278. // initialize service
  279. const PassportService = require('../service/passport');
  280. if (this.passportService == null) {
  281. this.passportService = new PassportService(this);
  282. }
  283. this.passportService.setupSerializer();
  284. // setup strategies
  285. try {
  286. this.passportService.setupStrategyById('local');
  287. this.passportService.setupStrategyById('ldap');
  288. this.passportService.setupStrategyById('saml');
  289. this.passportService.setupStrategyById('oidc');
  290. this.passportService.setupStrategyById('basic');
  291. this.passportService.setupStrategyById('google');
  292. this.passportService.setupStrategyById('github');
  293. this.passportService.setupStrategyById('twitter');
  294. }
  295. catch (err) {
  296. logger.error(err);
  297. }
  298. // add as a message handler
  299. if (this.s2sMessagingService != null) {
  300. this.s2sMessagingService.addMessageHandler(this.passportService);
  301. }
  302. return Promise.resolve();
  303. };
  304. Crowi.prototype.setupSearcher = async function() {
  305. this.searchService = new SearchService(this);
  306. };
  307. Crowi.prototype.setupMailer = async function() {
  308. const MailService = require('~/server/service/mail');
  309. this.mailService = new MailService(this);
  310. // add as a message handler
  311. if (this.s2sMessagingService != null) {
  312. this.s2sMessagingService.addMessageHandler(this.mailService);
  313. }
  314. };
  315. Crowi.prototype.autoInstall = function() {
  316. const isInstalled = this.configManager.getConfig('crowi', 'app:installed');
  317. const username = this.configManager.getConfig('crowi', 'autoInstall:adminUsername');
  318. if (isInstalled || username == null) {
  319. return;
  320. }
  321. logger.info('Start automatic installation');
  322. const firstAdminUserToSave = {
  323. username,
  324. name: this.configManager.getConfig('crowi', 'autoInstall:adminName'),
  325. email: this.configManager.getConfig('crowi', 'autoInstall:adminEmail'),
  326. password: this.configManager.getConfig('crowi', 'autoInstall:adminPassword'),
  327. admin: true,
  328. };
  329. const globalLang = this.configManager.getConfig('crowi', 'autoInstall:globalLang');
  330. const allowGuestMode = this.configManager.getConfig('crowi', 'autoInstall:allowGuestMode');
  331. const serverDate = this.configManager.getConfig('crowi', 'autoInstall:serverDate');
  332. const installerService = new InstallerService(this);
  333. try {
  334. installerService.install(firstAdminUserToSave, globalLang ?? 'en_US', {
  335. allowGuestMode,
  336. serverDate,
  337. });
  338. }
  339. catch (err) {
  340. logger.warn('Automatic installation failed.', err);
  341. }
  342. };
  343. Crowi.prototype.getTokens = function() {
  344. return this.tokens;
  345. };
  346. Crowi.prototype.start = async function() {
  347. const dev = process.env.NODE_ENV !== 'production';
  348. this.nextApp = next({ dev });
  349. await this.nextApp.prepare();
  350. // init CrowiDev
  351. if (dev) {
  352. const CrowiDev = require('./dev');
  353. this.crowiDev = new CrowiDev(this);
  354. this.crowiDev.init();
  355. }
  356. await this.init();
  357. await this.buildServer();
  358. const { express, configManager } = this;
  359. const app = (this.node_env === 'development') ? this.crowiDev.setupServer(express) : express;
  360. const httpServer = http.createServer(app);
  361. // setup terminus
  362. this.setupTerminus(httpServer);
  363. // attach to socket.io
  364. this.socketIoService.attachServer(httpServer);
  365. // listen
  366. const serverListening = httpServer.listen(this.port, () => {
  367. logger.info(`[${this.node_env}] Express server is listening on port ${this.port}`);
  368. if (this.node_env === 'development') {
  369. this.crowiDev.setupExpressAfterListening(express);
  370. }
  371. });
  372. // listen for promster
  373. if (configManager.getConfig('crowi', 'promster:isEnabled')) {
  374. const { createServer } = require('@promster/server');
  375. const promsterPort = configManager.getConfig('crowi', 'promster:port');
  376. createServer({ port: promsterPort }).then(() => {
  377. logger.info(`[${this.node_env}] Promster server is listening on port ${promsterPort}`);
  378. });
  379. }
  380. // setup Express Routes
  381. this.setupRoutesForPlugins();
  382. this.setupRoutesAtLast();
  383. // setup Global Error Handlers
  384. this.setupGlobalErrorHandlers();
  385. // Execute this asynchronously after the express server is ready so it does not block the ongoing process
  386. this.asyncAfterExpressServerReady();
  387. return serverListening;
  388. };
  389. Crowi.prototype.buildServer = async function() {
  390. const env = this.node_env;
  391. const express = require('express')();
  392. require('./express-init')(this, express);
  393. // use bunyan
  394. if (env === 'production') {
  395. const expressBunyanLogger = require('express-bunyan-logger');
  396. const logger = loggerFactory('express');
  397. express.use(expressBunyanLogger({
  398. logger,
  399. excludes: ['*'],
  400. }));
  401. }
  402. // use morgan
  403. else {
  404. const morgan = require('morgan');
  405. express.use(morgan('dev'));
  406. }
  407. this.express = express;
  408. };
  409. Crowi.prototype.setupTerminus = function(server) {
  410. createTerminus(server, {
  411. signals: ['SIGINT', 'SIGTERM'],
  412. onSignal: async() => {
  413. logger.info('Server is starting cleanup');
  414. await mongoose.disconnect();
  415. return;
  416. },
  417. onShutdown: async() => {
  418. logger.info('Cleanup finished, server is shutting down');
  419. },
  420. });
  421. };
  422. Crowi.prototype.setupRoutesForPlugins = function() {
  423. lsxRoutes(this, this.express);
  424. };
  425. /**
  426. * setup Express Routes
  427. * !! this must be at last because it includes '/*' route !!
  428. */
  429. Crowi.prototype.setupRoutesAtLast = function() {
  430. require('../routes')(this, this.express);
  431. };
  432. /**
  433. * setup global error handlers
  434. * !! this must be after the Routes setup !!
  435. */
  436. Crowi.prototype.setupGlobalErrorHandlers = function() {
  437. this.express.use(httpErrorHandler);
  438. };
  439. /**
  440. * require API for plugins
  441. *
  442. * @param {string} modulePath relative path from /lib/crowi/index.js
  443. * @return {module}
  444. *
  445. * @memberof Crowi
  446. */
  447. Crowi.prototype.require = function(modulePath) {
  448. return require(modulePath);
  449. };
  450. /**
  451. * setup GlobalNotificationService
  452. */
  453. Crowi.prototype.setUpGlobalNotification = async function() {
  454. const GlobalNotificationService = require('../service/global-notification');
  455. if (this.globalNotificationService == null) {
  456. this.globalNotificationService = new GlobalNotificationService(this);
  457. }
  458. };
  459. /**
  460. * setup UserNotificationService
  461. */
  462. Crowi.prototype.setUpUserNotification = async function() {
  463. if (this.userNotificationService == null) {
  464. this.userNotificationService = new UserNotificationService(this);
  465. }
  466. };
  467. /**
  468. * setup XssService
  469. */
  470. Crowi.prototype.setUpXss = async function() {
  471. const XssService = require('../service/xss');
  472. if (this.xssService == null) {
  473. this.xssService = new XssService(this.configManager);
  474. }
  475. };
  476. /**
  477. * setup AclService
  478. */
  479. Crowi.prototype.setUpAcl = async function() {
  480. if (this.aclService == null) {
  481. this.aclService = new AclService(this.configManager);
  482. }
  483. };
  484. /**
  485. * setup CustomizeService
  486. */
  487. Crowi.prototype.setUpCustomize = async function() {
  488. const CustomizeService = require('../service/customize');
  489. if (this.customizeService == null) {
  490. this.customizeService = new CustomizeService(this);
  491. this.customizeService.initCustomCss();
  492. this.customizeService.initCustomTitle();
  493. // add as a message handler
  494. if (this.s2sMessagingService != null) {
  495. this.s2sMessagingService.addMessageHandler(this.customizeService);
  496. }
  497. }
  498. };
  499. /**
  500. * setup AppService
  501. */
  502. Crowi.prototype.setUpApp = async function() {
  503. if (this.appService == null) {
  504. this.appService = new AppService(this);
  505. // add as a message handler
  506. const isInstalled = this.configManager.getConfig('crowi', 'app:installed');
  507. if (this.s2sMessagingService != null && !isInstalled) {
  508. this.s2sMessagingService.addMessageHandler(this.appService);
  509. }
  510. }
  511. };
  512. /**
  513. * setup FileUploadService
  514. */
  515. Crowi.prototype.setUpFileUpload = async function(isForceUpdate = false) {
  516. if (this.fileUploadService == null || isForceUpdate) {
  517. this.fileUploadService = require('../service/file-uploader')(this);
  518. }
  519. };
  520. /**
  521. * setup FileUploaderSwitchService
  522. */
  523. Crowi.prototype.setUpFileUploaderSwitchService = async function() {
  524. const FileUploaderSwitchService = require('../service/file-uploader-switch');
  525. this.fileUploaderSwitchService = new FileUploaderSwitchService(this);
  526. // add as a message handler
  527. if (this.s2sMessagingService != null) {
  528. this.s2sMessagingService.addMessageHandler(this.fileUploaderSwitchService);
  529. }
  530. };
  531. /**
  532. * setup AttachmentService
  533. */
  534. Crowi.prototype.setupAttachmentService = async function() {
  535. if (this.attachmentService == null) {
  536. this.attachmentService = new AttachmentService(this);
  537. }
  538. };
  539. /**
  540. * setup RestQiitaAPIService
  541. */
  542. Crowi.prototype.setUpRestQiitaAPI = async function() {
  543. const RestQiitaAPIService = require('../service/rest-qiita-API');
  544. if (this.restQiitaAPIService == null) {
  545. this.restQiitaAPIService = new RestQiitaAPIService(this);
  546. }
  547. };
  548. Crowi.prototype.setupUserGroupService = async function() {
  549. const UserGroupService = require('../service/user-group');
  550. if (this.userGroupService == null) {
  551. this.userGroupService = new UserGroupService(this);
  552. return this.userGroupService.init();
  553. }
  554. };
  555. Crowi.prototype.setUpGrowiBridge = async function() {
  556. const GrowiBridgeService = require('../service/growi-bridge');
  557. if (this.growiBridgeService == null) {
  558. this.growiBridgeService = new GrowiBridgeService(this);
  559. }
  560. };
  561. Crowi.prototype.setupExport = async function() {
  562. const ExportService = require('../service/export');
  563. if (this.exportService == null) {
  564. this.exportService = new ExportService(this);
  565. }
  566. };
  567. Crowi.prototype.setupImport = async function() {
  568. const ImportService = require('../service/import');
  569. if (this.importService == null) {
  570. this.importService = new ImportService(this);
  571. }
  572. };
  573. Crowi.prototype.setupPageService = async function() {
  574. if (this.pageService == null) {
  575. this.pageService = new PageService(this);
  576. }
  577. if (this.pageGrantService == null) {
  578. this.pageGrantService = new PageGrantService(this);
  579. }
  580. if (this.pageOperationService == null) {
  581. this.pageOperationService = new PageOperationService(this);
  582. await this.pageOperationService.init();
  583. }
  584. };
  585. Crowi.prototype.setupInAppNotificationService = async function() {
  586. const InAppNotificationService = require('../service/in-app-notification');
  587. if (this.inAppNotificationService == null) {
  588. this.inAppNotificationService = new InAppNotificationService(this);
  589. }
  590. };
  591. Crowi.prototype.setupActivityService = async function() {
  592. const ActivityService = require('../service/activity');
  593. if (this.activityService == null) {
  594. this.activityService = new ActivityService(this);
  595. await this.activityService.createTtlIndex();
  596. }
  597. };
  598. Crowi.prototype.setupCommentService = async function() {
  599. const CommentService = require('../service/comment');
  600. if (this.commentService == null) {
  601. this.commentService = new CommentService(this);
  602. }
  603. };
  604. Crowi.prototype.setupSyncPageStatusService = async function() {
  605. const SyncPageStatusService = require('../service/system-events/sync-page-status');
  606. if (this.syncPageStatusService == null) {
  607. this.syncPageStatusService = new SyncPageStatusService(this, this.s2sMessagingService, this.socketIoService);
  608. // add as a message handler
  609. if (this.s2sMessagingService != null) {
  610. this.s2sMessagingService.addMessageHandler(this.syncPageStatusService);
  611. }
  612. }
  613. };
  614. Crowi.prototype.setupSlackIntegrationService = async function() {
  615. if (this.slackIntegrationService == null) {
  616. this.slackIntegrationService = new SlackIntegrationService(this);
  617. }
  618. // add as a message handler
  619. if (this.s2sMessagingService != null) {
  620. this.s2sMessagingService.addMessageHandler(this.slackIntegrationService);
  621. }
  622. };
  623. export default Crowi;