app.ts 1017 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import Logger from 'bunyan';
  2. import loggerFactory from '~/utils/logger';
  3. import { hasProcessFlag } from '~/utils/process-utils';
  4. import Crowi from './crowi';
  5. const logger: Logger = loggerFactory('growi');
  6. /** **********************************
  7. * Main Process
  8. ********************************** */
  9. process.on('uncaughtException', (err?: Error) => {
  10. logger.error('Uncaught Exception: ', err);
  11. });
  12. process.on('unhandledRejection', (reason, p) => {
  13. logger.error('Unhandled Rejection: Promise:', p, 'Reason:', reason);
  14. });
  15. async function main() {
  16. try {
  17. // eslint-disable-next-line @typescript-eslint/no-var-requires
  18. const growi = new Crowi();
  19. const server = await growi.start();
  20. if (hasProcessFlag('ci')) {
  21. logger.info('"--ci" flag is detected. Exit process.');
  22. server.close(() => {
  23. process.exit();
  24. });
  25. }
  26. }
  27. catch (err) {
  28. logger.error('An error occurred, unable to start the server');
  29. logger.error(err);
  30. process.exit(1);
  31. }
  32. }
  33. main();