-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
executable file
·42 lines (32 loc) · 980 Bytes
/
app.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
const express = require("express");
const app = express();
const mongoose = require("mongoose");
const userRouter = require("./src/routes/UserRoutes");
const roomRouter = require("./src/routes/RoomRoutes");
const bookingRouter = require("./src/routes/BookingsRoute");
require("dotenv").config();
const cors = require("cors");
const corsOption = {
origin: ["http://localhost:3000"],
};
app.use(cors(corsOption));
const port = process.env.PORT;
async function main() {
await mongoose.connect(process.env.MONGODB_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
}
main()
.then(() => console.log("MongoDB connection successful."))
.catch(console.log);
app.use(express.json());
app.get("/", (req, res) => {
res.json({ message: "Hello World" });
});
app.use("/api/users", userRouter);
app.use("/api/rooms", roomRouter);
app.use("/api/bookings", bookingRouter);
app.listen(port, () => {
console.log(`🚀 Server running on port: ${port}`);
});