diff --git a/src/server.ts b/src/server.ts index 550b532f..1b9a5f65 100644 --- a/src/server.ts +++ b/src/server.ts @@ -1,6 +1,5 @@ -import "reflect-metadata"; - import "express-async-errors"; +import "reflect-metadata"; import { appEnv } from "@providers/config/env"; import { @@ -17,8 +16,6 @@ import { router } from "@providers/server/Router"; import { app } from "@providers/server/app"; import { NewRelicTransactionCategory } from "@providers/types/NewRelicTypes"; import { EnvType } from "@rpg-engine/shared/dist"; -import * as Sentry from "@sentry/node"; -import * as Tracing from "@sentry/tracing"; import dayjs from "dayjs"; import duration from "dayjs/plugin/duration"; @@ -37,47 +34,27 @@ const server = app.listen(port, async () => { NewRelicTransactionCategory.Operation, "ServerBootstrap", async () => { - const endTime = Date.now(); - const bootstrapTime = endTime - startTime; - - await database.initialize(); - await redisManager.connect(); + // Run database and Redis initialization tasks in parallel + await Promise.all([database.initialize(), redisManager.connect(), socketAdapter.init(appEnv.socket.type)]); + // Start cron jobs cronJobs.start(); - await socketAdapter.init(appEnv.socket.type); - app.use(Sentry.Handlers.requestHandler()); - app.use(Sentry.Handlers.tracingHandler()); app.use(router); - app.use(Sentry.Handlers.errorHandler()); app.use(errorHandlerMiddleware); - //! Dev Warning: If you want to add a new operation on server bootstrap, make sure to add it to one of the methods below (check if needs to be executed in all PM2 instances or not.) - + // Perform server bootstrap operations await serverBootstrap.performOneTimeOperations(); - await serverBootstrap.performMultipleInstancesOperations(); if (appEnv.general.ENV === EnvType.Production) { - Sentry.init({ - dsn: appEnv.general.SENTRY_DNS_URL, - integrations: [ - // enable HTTP calls tracing - new Sentry.Integrations.Http({ tracing: true }), - // enable Express.js middleware tracing - new Tracing.Integrations.Express({ app }), - ], - - // Set tracesSampleRate to 1.0 to capture 100% - // of transactions for performance monitoring. - // We recommend adjusting this value in production - tracesSampleRate: 1.0, - }); - console.log(`✅ Application started succesfully on PMID ${process.env.pm_id}`); } + const endTime = Date.now(); + const bootstrapTime = endTime - startTime; + serverHelper.showBootstrapMessage({ appName: appEnv.general.APP_NAME!, port: appEnv.general.SERVER_PORT!,