forked from Canteen-Connect/canteen-connect-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
44 lines (34 loc) · 1.05 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import express from "express";
import morgan from "morgan";
import dotenv from "dotenv";
import cors from "cors";
import { dbConnect } from "./config/dbConnect";
import rootRoutes from "./routes";
import swaggerUi from "swagger-ui-express";
import swaggerJsdoc from "swagger-jsdoc";
import swaggerOptions from "./swagger";
import http from "http";
import { initSocketServer } from "./socket";
// Initialize environment variables
dotenv.config();
const app = express();
const swaggerSpec = swaggerJsdoc(swaggerOptions);
const server = http.createServer(app);
const io = initSocketServer(server);
// Middleware setup
app.use(express.json());
app.use(morgan("dev"));
app.use(cors());
// Serve Swagger API Documentation
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerSpec));
// Routing setup
app.use("/api/v1", rootRoutes);
// Start the HTTP server (ensure it's `server.listen`, not `app.listen`)
server.listen(3000, () => {
console.log("Server is running on port 3000");
});
// Database connection
const main = async () => {
await dbConnect();
};
main();