index.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // ===========================================
  2. // Wiki.js
  3. // Licensed under AGPLv3
  4. // ===========================================
  5. const path = require('path')
  6. const { DateTime } = require('luxon')
  7. const semver = require('semver')
  8. const nanoid = require('nanoid').customAlphabet('1234567890abcdef', 10)
  9. if (!semver.satisfies(process.version, '>=18')) {
  10. console.error('ERROR: Node.js 18.x or later required!')
  11. process.exit(1)
  12. }
  13. let WIKI = {
  14. IS_DEBUG: process.env.NODE_ENV === 'development',
  15. ROOTPATH: process.cwd(),
  16. INSTANCE_ID: nanoid(10),
  17. SERVERPATH: path.join(process.cwd(), 'server'),
  18. Error: require('./helpers/error'),
  19. configSvc: require('./core/config'),
  20. kernel: require('./core/kernel'),
  21. sites: {},
  22. sitesMappings: {},
  23. startedAt: DateTime.utc(),
  24. storage: {
  25. defs: [],
  26. modules: []
  27. }
  28. }
  29. global.WIKI = WIKI
  30. WIKI.configSvc.init()
  31. // ----------------------------------------
  32. // Init Logger
  33. // ----------------------------------------
  34. WIKI.logger = require('./core/logger').init()
  35. // ----------------------------------------
  36. // Start Kernel
  37. // ----------------------------------------
  38. WIKI.kernel.init()
  39. // ----------------------------------------
  40. // Register exit handler
  41. // ----------------------------------------
  42. process.on('SIGINT', () => {
  43. WIKI.kernel.shutdown()
  44. })
  45. process.on('message', (msg) => {
  46. if (msg === 'shutdown') {
  47. WIKI.kernel.shutdown()
  48. }
  49. })