2023-11-17 09:03:31 +07:00
|
|
|
import "dotenv/config";
|
|
|
|
|
import express from "express";
|
|
|
|
|
import swaggerUi from "swagger-ui-express";
|
|
|
|
|
import cors from "cors";
|
|
|
|
|
|
|
|
|
|
import { RegisterRoutes } from "./routes";
|
|
|
|
|
import errorHandler from "./middlewares/exception";
|
2023-11-27 09:45:30 +07:00
|
|
|
import rabbitmq from "./rabbitmq";
|
2023-11-17 09:03:31 +07:00
|
|
|
|
|
|
|
|
import swaggerSpecs from "./swagger.json";
|
2023-11-27 09:45:30 +07:00
|
|
|
import { handler as amqHandler } from "./rabbitmq/handler";
|
2023-11-17 09:03:31 +07:00
|
|
|
|
|
|
|
|
const PORT = +(process.env.PORT || 80);
|
|
|
|
|
|
|
|
|
|
const app = express();
|
|
|
|
|
const router = express.Router();
|
|
|
|
|
|
|
|
|
|
if (process.env.NODE_ENV !== "production") app.use(cors());
|
|
|
|
|
|
|
|
|
|
app.use(express.json());
|
|
|
|
|
app.use(express.urlencoded({ extended: true }));
|
|
|
|
|
app.use("/docs", swaggerUi.serve, swaggerUi.setup(swaggerSpecs, { explorer: false }));
|
|
|
|
|
|
|
|
|
|
RegisterRoutes(router);
|
|
|
|
|
|
|
|
|
|
app.use(swaggerSpecs.basePath, router);
|
|
|
|
|
app.use(errorHandler);
|
|
|
|
|
|
2023-11-30 10:10:51 +07:00
|
|
|
app.use((_req, res, _next) => {
|
2023-11-30 09:40:00 +07:00
|
|
|
res.sendFile(`${process.cwd()}/static/index.html`);
|
|
|
|
|
});
|
2023-11-29 22:42:33 +07:00
|
|
|
|
2023-11-22 16:12:03 +07:00
|
|
|
app.listen(PORT, "0.0.0.0", () =>
|
2023-11-27 14:39:44 +07:00
|
|
|
console.log(`[APP] Application is running on http://localhost:${PORT}`),
|
2023-11-22 16:12:03 +07:00
|
|
|
);
|
2023-11-27 09:45:30 +07:00
|
|
|
|
|
|
|
|
rabbitmq.init(amqHandler).catch((e) => console.error(e));
|