-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
93 lines (68 loc) · 2.49 KB
/
index.js
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// const express = require("express");
// const app = express();
// const connectDb = require('./db.js');
// const PORT = process.env.PORT || 3000;
// connectDb();
// // Middleware for parsing JSON data
// app.use(express.json());
// // Middleware for parsing URL-encoded data
// app.use(express.urlencoded({ extended: false }));
// //Import and use the Authentication Route
// const authRoutes = require("./routes/authRoute.js");
// app.use('/auth', authRoutes);
// //Import and use the OTPRoute
// const otpRoutes = require("./routes/otpRoute.js");
// app.use('/verify-otp', otpRoutes);
// // Error handling middleware
// app.use((err, req, res, next) => {
// console.error(err);
// res.status(500).json({ message: 'Something went wrong' });
// });
// app.listen(PORT, () => {
// console.log(`Server is running on ${PORT}`)
// });
// Load environment variables from .env file
require('dotenv').config(); // Make sure this is at the top
const express = require("express");
const connectDb = require('./db.js');
const app = express();
const PORT = process.env.PORT || 3000;
// Connect to MongoDB
connectDb();
// Middleware for parsing JSON data
app.use(express.json());
// Middleware for parsing URL-encoded data
app.use(express.urlencoded({ extended: false }));
// Import and use the Authentication Route
const authRoutes = require("./routes/authRoute.js");
app.use('/auth', authRoutes);
// Import and use the OTP Route
const otpRoutes = require("./routes/otpRoute.js");
app.use('/verify-otp', otpRoutes);
// Import and use the Voting route
const votingRoutes = require("./routes/votingRoute.js");
app.use('/voting', votingRoutes);
// Import and use the Member route
const memberRoutes = require("./routes/memberRoute.js");
app.use('/members', memberRoutes);
// Import and use the submit forms
const submitFormAnswersRoutes = require("./routes/submitFormAnswersRoute.js");
app.use('/submitFormAnswers',submitFormAnswersRoutes);
// Import and use the match route
const matchRoutes = require("./routes/matchRoute.js");
app.use('/match', matchRoutes);
// highlights
const highlightRoutes = require('./routes/highlightRoute')
app.use('/highlight', highlightRoutes );
// Event of Club
const eventRoutes = require('./routes/eventRoute')
app.use('/event', eventRoutes );
// Error handling middleware
app.use((err, req, res, next) => {
console.error(err);
res.status(500).json({ message: 'Something went wrong' });
});
// Start the server
app.listen(PORT, () => {
console.log(`Server is running on ${PORT}`);
});