2024-09-13 13:03:35 +00:00
|
|
|
import express from "express";
|
|
|
|
|
import cors from "cors";
|
|
|
|
|
import dotenv from "dotenv";
|
2024-08-12 02:44:06 +00:00
|
|
|
import { testConnection } from "./database/db.js";
|
|
|
|
|
import router from "./routes/index.js";
|
2024-09-13 13:03:35 +00:00
|
|
|
import cookieParser from "cookie-parser";
|
2024-10-28 09:18:25 +00:00
|
|
|
import promBundle from "express-prom-bundle";
|
2024-08-12 02:44:06 +00:00
|
|
|
|
|
|
|
|
dotenv.config();
|
|
|
|
|
const app = express();
|
|
|
|
|
|
2024-10-28 09:18:25 +00:00
|
|
|
const metricsMiddleware = promBundle({
|
|
|
|
|
includeMethod: true,
|
|
|
|
|
includePath: true,
|
|
|
|
|
includeStatusCode: true,
|
|
|
|
|
promClient: {
|
|
|
|
|
collectDefaultMetrics: {},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.use(metricsMiddleware);
|
|
|
|
|
|
2024-09-13 13:03:35 +00:00
|
|
|
const corsOptions = {
|
2024-10-28 09:18:25 +00:00
|
|
|
origin: `${process.env.CLIENT_URL}`,
|
|
|
|
|
methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
|
|
|
|
|
allowedHeaders: ["Content-Type", "Authorization"],
|
|
|
|
|
credentials: true,
|
2024-09-13 13:03:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
app.use(cors(corsOptions));
|
|
|
|
|
|
2024-08-12 02:44:06 +00:00
|
|
|
app.use(cookieParser());
|
|
|
|
|
app.use(express.json());
|
2024-09-13 13:03:35 +00:00
|
|
|
app.use(express.urlencoded({ extended: true }));
|
2024-08-12 02:44:06 +00:00
|
|
|
app.use(router);
|
2024-09-13 13:03:35 +00:00
|
|
|
app.use(express.static("public"));
|
2024-08-12 02:44:06 +00:00
|
|
|
|
|
|
|
|
app.listen(process.env.APP_PORT, () => {
|
2024-09-13 13:03:35 +00:00
|
|
|
testConnection();
|
2024-10-28 09:18:25 +00:00
|
|
|
console.log(`Server running on port ${process.env.APP_PORT}`);
|
2024-09-13 13:03:35 +00:00
|
|
|
});
|