49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
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 * as cron from "node-cron";
|
|
import error from "./middlewares/error";
|
|
import { AppDataSource } from "./database/data-source";
|
|
import { RegisterRoutes } from "./routes";
|
|
import logMiddleware from "./middlewares/logs";
|
|
import { DateSerializer } from "./interfaces/date-serializer";
|
|
|
|
async function main() {
|
|
await AppDataSource.initialize();
|
|
|
|
// Setup custom Date serialization for local timezone
|
|
DateSerializer.setupDateSerialization();
|
|
|
|
const app = express();
|
|
|
|
app.use(
|
|
cors({
|
|
origin: "*",
|
|
}),
|
|
);
|
|
app.use(express.json());
|
|
app.use(express.urlencoded({ extended: true }));
|
|
app.use(logMiddleware);
|
|
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,
|
|
() => (
|
|
console.log(`[APP] Application is running on: http://localhost:${APP_PORT}`),
|
|
console.log(`[APP] Swagger on: http://localhost:${APP_PORT}/api-docs`)
|
|
),
|
|
);
|
|
}
|
|
|
|
main();
|