first
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import "reflect-metadata";
|
||||
import { createServer } from "http";
|
||||
|
||||
import { config } from "dotenv";
|
||||
import { Container } from "inversify";
|
||||
|
||||
config();
|
||||
|
||||
import { App } from "./app";
|
||||
import { Logger } from "./core/logging/logger";
|
||||
import { connectMongo } from "./db/connection";
|
||||
import { IOCTYPES } from "./IOC/ioc.types";
|
||||
import { ChatGateway } from "./modules/chat/chat.gateway";
|
||||
import { StartWorker } from "./queues";
|
||||
import { gracefulShutdown } from "./utils/shutdown.utils";
|
||||
|
||||
const PORT = parseInt(process.env.PORT) || 4000;
|
||||
const logger = new Logger();
|
||||
async function bootStrap() {
|
||||
try {
|
||||
await connectMongo();
|
||||
logger.info("mongodb connected");
|
||||
//
|
||||
const container = new Container();
|
||||
const app = new App(container).Build();
|
||||
const server = createServer(app);
|
||||
//
|
||||
const chatGateway = container.get<ChatGateway>(IOCTYPES.ChatGateway);
|
||||
const wsServer = chatGateway.initialize(server);
|
||||
|
||||
const worker = await StartWorker();
|
||||
|
||||
//
|
||||
server.listen(PORT, "0.0.0.0", () => {
|
||||
logger.info(`listening on http://localhost:${PORT}`);
|
||||
logger.info(`swagger documentation is serving on http://localhost:${PORT}/api-docs`);
|
||||
});
|
||||
|
||||
process.on("SIGINT", () => gracefulShutdown("SIGINT", server, wsServer, worker[0], logger));
|
||||
|
||||
process.on("SIGTERM", () => gracefulShutdown("SIGTERM", server, wsServer, worker[0], logger));
|
||||
} catch (error) {
|
||||
logger.error("Error starting the server.", error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
bootStrap();
|
||||
|
||||
process.on("uncaughtException", function (err) {
|
||||
logger.error("Uncaught exception", err);
|
||||
});
|
||||
|
||||
process.on("unhandledRejection", (reason, promise) => {
|
||||
logger.error("Unhandled Rejection at: Promise", { promise, reason });
|
||||
});
|
||||
Reference in New Issue
Block a user