-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
32 lines (25 loc) · 915 Bytes
/
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
const express = require("express");
const cors = require("cors");
const dotenv = require("dotenv").config();
const connectDB = require("./config/db");
const initializeSocket = require("./sockets/sockets");
const PORT = process.env.PORT || 3000;
connectDB();
const app = express();
// Middleware
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
// Routes
app.use("/api/users", require("./routes/userRoutes"));
app.use("/api/channels", require("./routes/channelRoutes"));
app.use("/api/messages", require("./routes/singleMessageRoutes"));
app.use("/api/directMessages", require("./routes/directMessagesRoutes"));
app.use("/api/profile", require("./routes/profileRoutes"));
app.get("/", (req, res) => {
res.send("Welcome to the root URL!");
});
const server = app.listen(PORT, () => {
console.log(`Server listening on port ${PORT}`);
});
initializeSocket(server);