index.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. const fs = require('fs-extra')
  10. if (!semver.satisfies(process.version, '>=18')) {
  11. console.error('ERROR: Node.js 18.x or later required!')
  12. process.exit(1)
  13. }
  14. if (fs.pathExistsSync('./package.json')) {
  15. console.error('ERROR: Must run server from the parent directory!')
  16. process.exit(1)
  17. }
  18. let WIKI = {
  19. IS_DEBUG: process.env.NODE_ENV === 'development',
  20. ROOTPATH: process.cwd(),
  21. INSTANCE_ID: nanoid(10),
  22. SERVERPATH: path.join(process.cwd(), 'server'),
  23. Error: require('./helpers/error'),
  24. configSvc: require('./core/config'),
  25. kernel: require('./core/kernel'),
  26. sites: {},
  27. sitesMappings: {},
  28. startedAt: DateTime.utc(),
  29. storage: {
  30. defs: [],
  31. modules: []
  32. }
  33. }
  34. global.WIKI = WIKI
  35. WIKI.configSvc.init()
  36. // ----------------------------------------
  37. // Init Logger
  38. // ----------------------------------------
  39. WIKI.logger = require('./core/logger').init()
  40. // ----------------------------------------
  41. // Start Kernel
  42. // ----------------------------------------
  43. WIKI.kernel.init()
  44. // ----------------------------------------
  45. // Register exit handler
  46. // ----------------------------------------
  47. process.on('SIGINT', () => {
  48. WIKI.kernel.shutdown()
  49. })
  50. process.on('message', (msg) => {
  51. if (msg === 'shutdown') {
  52. WIKI.kernel.shutdown()
  53. }
  54. })