app.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import type Logger from 'bunyan';
  2. import { initServiceInstanceId, startInstrumentation } from '~/features/opentelemetry/server';
  3. import loggerFactory from '~/utils/logger';
  4. import { hasProcessFlag } from '~/utils/process-utils';
  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. // start OpenTelemetry
  18. await startInstrumentation();
  19. const Crowi = (await import('./crowi')).default;
  20. const growi = new Crowi();
  21. const server = await growi.start();
  22. await initServiceInstanceId();
  23. if (hasProcessFlag('ci')) {
  24. logger.info('"--ci" flag is detected. Exit process.');
  25. server.close(() => {
  26. process.exit();
  27. });
  28. }
  29. }
  30. catch (err) {
  31. logger.error('An error occurred, unable to start the server');
  32. logger.error(err);
  33. process.exit(1);
  34. }
  35. }
  36. main();