index.mjs 1.6 KB

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