-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
57 lines (46 loc) · 1.59 KB
/
server.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
// // server.js
// const express = require("express");
// const dotenv = require("dotenv");
// const cors = require("cors");
// const connectDB = require("./config/db");
// const swaggerDocs = require("./swagger");
// // Load environment variables
// dotenv.config();
// // Connect to MongoDB
// connectDB();
// const app = express();
// swaggerDocs(app);
// app.use(express.json());
// app.use(cors());
// // Routes
// app.use("/api/auth", require("./routes/authRoutes"));
// app.use("/api/rides", require("./routes/rideRoutes"));
// const PORT = process.env.PORT || 5000;
// app.listen(PORT, () => console.log(`Server running on port ${PORT}`));
const express = require("express");
const mongoose = require("mongoose");
const authRoutes = require("./routes/authRoutes");
const rideRoutes = require("./routes/rideRoutes");
const bookingRoutes = require("./routes/bookingRoutes");
require("dotenv").config();
const app = express();
const port = process.env.PORT || 5000;
// Middleware
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// Routes
app.use("/api/auth", authRoutes);
app.use("/api/rides", rideRoutes); // Ensure this is correctly configured
app.use("/api/bookings", bookingRoutes); // Ensure this is correctly configured
// Connect to MongoDB
mongoose
.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => console.log("MongoDB connected"))
.catch((err) => console.error("MongoDB connection error:", err));
// Start the server
app.listen(port, "192.168.131.119", () => {
console.log(`Server running on port ${port}`);
});