app.js 960 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /**
  2. * Growi::app.js
  3. *
  4. * @package growi
  5. * @author Yuki Takei <yuki@weseek.co.jp>
  6. */
  7. require('module-alias/register');
  8. const logger = require('@alias/logger')('growi');
  9. const helpers = require('@commons/util/helpers');
  10. const growi = new (require('./crowi'))(helpers.root(), process.env);
  11. /************************************
  12. * Main Process
  13. ***********************************/
  14. process.on('uncaughtException', (err) => {
  15. logger.error('Uncaught Exception: ', err);
  16. });
  17. process.on('unhandledRejection', (reason, p) => {
  18. logger.error('Unhandled Rejection: Promise:', p, 'Reason:', reason);
  19. });
  20. growi.start()
  21. .then(express => {
  22. if (helpers.hasProcessFlag('ci')) {
  23. logger.info('"--ci" flag is detected. Exit process.');
  24. express.close(() => {
  25. process.exit();
  26. });
  27. }
  28. })
  29. .catch(err => {
  30. logger.error('An error occurred, unable to start the server');
  31. logger.error(err);
  32. process.exit(1);
  33. });