2
0

index.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // ===========================================
  2. // Wiki.js
  3. // Licensed under AGPLv3
  4. // ===========================================
  5. const path = require('path')
  6. const { nanoid } = require('nanoid')
  7. const { DateTime } = require('luxon')
  8. const { gte } = require('semver')
  9. // ----------------------------------------
  10. // Check Node.js version
  11. // ----------------------------------------
  12. if (gte(process.version, '21.0.0')) {
  13. console.error('You\'re using an unsupported Node.js version. Please read the requirements.')
  14. process.exit(1)
  15. }
  16. // ----------------------------------------
  17. // Init WIKI instance
  18. // ----------------------------------------
  19. let WIKI = {
  20. IS_DEBUG: process.env.NODE_ENV === 'development',
  21. IS_MASTER: true,
  22. ROOTPATH: process.cwd(),
  23. INSTANCE_ID: nanoid(10),
  24. SERVERPATH: path.join(process.cwd(), 'server'),
  25. Error: require('./helpers/error'),
  26. configSvc: require('./core/config'),
  27. kernel: require('./core/kernel'),
  28. startedAt: DateTime.utc()
  29. }
  30. global.WIKI = WIKI
  31. WIKI.configSvc.init()
  32. // ----------------------------------------
  33. // Init Logger
  34. // ----------------------------------------
  35. WIKI.logger = require('./core/logger').init('MASTER')
  36. // ----------------------------------------
  37. // Start Kernel
  38. // ----------------------------------------
  39. WIKI.kernel.init()
  40. // ----------------------------------------
  41. // Register exit handler
  42. // ----------------------------------------
  43. process.on('SIGTERM', () => {
  44. WIKI.kernel.shutdown()
  45. })
  46. process.on('SIGINT', () => {
  47. WIKI.kernel.shutdown()
  48. })
  49. process.on('message', (msg) => {
  50. if (msg === 'shutdown') {
  51. WIKI.kernel.shutdown()
  52. }
  53. })