-
Notifications
You must be signed in to change notification settings - Fork 5
/
app.js
45 lines (36 loc) · 1.05 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
const express = require("express");
const app = express();
const multer = require("multer");
const port = 8000;
const session = require("express-session");
const http = require("http").Server(app);
const io = require("socket.io")(http);
const router = require("./routes");
const apiRouter = require("./routes/api");
const sessionObj = {
secret: "wegf6124@#$@#!", // salt -> 암호화를 할 때 필요한 요소값
resave: false,
saveUninitialized: true,
};
app.use(session(sessionObj));
app.use("/static", express.static("static"));
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use("/api", apiRouter);
app.use("/", router);
app.set("view engine", "ejs");
// let maxAge = 60 * 1000;
io.on("connection", (socket) => {
console.log(socket.id);
socket.on("roomentry", (msg) => {
console.log("msg", msg);
socket.join(msg);
});
socket.on("sendto", (msg) => {
console.log("msg", msg);
socket.broadcast.to(msg.roomname).emit("recieve", msg.msg);
});
});
http.listen(port, () => {
console.log("Server port : ", port);
});