hrms-edm/Services/server/src/app.ts
2023-11-22 16:16:27 +07:00

30 lines
816 B
TypeScript

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";
import swaggerSpecs from "./swagger.json";
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(express.static("static"));
app.use("/docs", swaggerUi.serve, swaggerUi.setup(swaggerSpecs, { explorer: false }));
RegisterRoutes(router);
app.use(swaggerSpecs.basePath, router);
app.use(errorHandler);
app.listen(PORT, "0.0.0.0", () =>
console.log(`Application is running on http://localhost:${PORT}`),
);