hrms-api-probation/src/app.ts

45 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-09-05 13:59:43 +07:00
import "dotenv/config";
import "reflect-metadata";
import cors from "cors";
import express from "express";
import swaggerUi from "swagger-ui-express";
import swaggerDocument from "./swagger.json";
import error from "./middlewares/error";
import { AppDataSource } from "./database/data-source";
import { RegisterRoutes } from "./routes";
2024-09-05 16:56:22 +07:00
import logMiddleware from "./middlewares/logs";
2024-09-05 13:59:43 +07:00
async function main() {
await AppDataSource.initialize();
const app = express();
app.use(
cors({
origin: "*",
2024-09-05 16:56:22 +07:00
}),
2024-09-05 13:59:43 +07:00
);
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
2024-09-05 16:56:22 +07:00
app.use(logMiddleware);
2024-09-05 13:59:43 +07:00
app.use("/", express.static("static"));
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
RegisterRoutes(app);
app.use(error);
const APP_HOST = process.env.APP_HOST || "0.0.0.0";
const APP_PORT = +(process.env.APP_PORT || 3000);
app.listen(
APP_PORT,
APP_HOST,
() => (
2024-09-05 16:56:22 +07:00
console.log(`[APP] Application is running on: http://localhost:${APP_PORT}`),
2024-09-05 13:59:43 +07:00
console.log(`[APP] Swagger on: http://localhost:${APP_PORT}/api-docs`)
2024-09-05 16:56:22 +07:00
),
2024-09-05 13:59:43 +07:00
);
}
main();