-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
36 lines (29 loc) · 893 Bytes
/
Copy pathindex.js
File metadata and controls
36 lines (29 loc) · 893 Bytes
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
const path = require("path");
const express = require("express");
const { createServer } = require("http");
const socketio = require("socket.io");
const session = require("express-session");
require("dotenv").config();
const socketHandler = require("./sockets");
const app = express();
const httpServer = createServer(app);
const io = socketio(httpServer);
const port = process.env.PORT || 3000;
const sessionMiddleware = session({
secret: process.env.SECRET_KEY,
saveUninitialized: true,
resave: false,
});
const connect = (middleware) => {
return (socket, next) => {
middleware(socket.request, {}, next);
};
};
app.use(sessionMiddleware);
app.use(express.static(path.join(__dirname, "public")));
app.set("trust proxy", 1);
io.use(connect(sessionMiddleware));
io.on("connection", socketHandler);
httpServer.listen(port, () => {
console.log("Server running on port", port);
});