-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
41 lines (32 loc) · 1.16 KB
/
Copy pathserver.js
File metadata and controls
41 lines (32 loc) · 1.16 KB
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
/**
* -------------------------------------------------------------------
* Author: Sasmithx
* GitHub: https://github.com/sasmithx
* Website: https://sasmithx.com
* -------------------------------------------------------------------
* Created: 2/12/2025 10:34 AM
* Project: VanguardVote-BACKEND
* -------------------------------------------------------------------
*/
require("dotenv").config();
const express = require("express");
const cors = require("cors");
const path = require("path");
const authRoutes = require("./routes/authRoutes")
const pollRoutes = require("./routes/pollRoutes")
const connectDB = require("./config/db");
const app = express();
//Middleware to handle CORS
app.use(cors({
origin: process.env.CLIENT_URL || "*",
methods: ["GET", "POST", "PUT", "DELETE"],
allowedHeaders: ["Content-Type", "Authorization"],
}));
app.use(express.json());
connectDB();
app.use("/api/v1/auth", authRoutes);
app.use("/api/v1/poll", pollRoutes);
//Serve uploads folder
app.use("/uploads", express.static(path.join(__dirname, "/uploads")));
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => console.log(`Server running on port ${PORT}`));