-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
54 lines (39 loc) · 1.35 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
const express = require("express");
const http = require("http");
const bodyParser = require("body-parser");
const cors = require("cors");
const userRoute = require("./routes/userRoute");
const chatRoute = require("./routes/chatRoute");
const session = require("express-session");
const cookieParser = require("cookie-parser");
require("./db/connect");
require("dotenv").config();
const app = express();
const server = http.createServer(app);
// Configuring session middleware for session management
app.use(session({
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: false
}));
// Parsing cookies with cookie-parser middleware
app.use(cookieParser());
// Enabling CORS (Cross-Origin Resource Sharing)
app.use(cors());
// Parsing JSON bodies and URL-encoded bodies
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.urlencoded({ extended: true }));
// Setting the view engine and views directory
app.set("view engine", "ejs");
app.set("views", "./views");
app.use(express.static("public"));
app.use("/", userRoute);
app.use("/", chatRoute);
const PORT = process.env.PORT || 8000;
// Setting up WebSocket for real-time communication
const socketSetup = require("./webSocket/socket");
socketSetup(server);
server.listen(PORT, () => {
console.log(`Server Running at PORT ${PORT}`);
});