-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
56 lines (47 loc) · 1.63 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require('dotenv').config();
global.sessions = {};
global.io;
const express = require('express');
const http = require('http');
const { Server } = require("socket.io");
const app = express();
const server = http.createServer(app);
global.io = new Server(server);
const port = process.env.PORT || 9999;
var fs = require("fs");
var path = require("path");
const morgan = require("morgan");
const { loadAndInitializeActiveSessions } = require('./app/lib/loadSession');
const { synchronizeModels } = require('./app/models');
const { startSession } = require('./app/lib/startSession');
synchronizeModels()
loadAndInitializeActiveSessions(io);
app.use(express.json());
app.use(morgan("combined"));
app.set('view engine', 'pug');
app.set('views', './public'); // the directory where your Pug templates are located
app.use(express.static(path.join(__dirname, 'public')));
io.on('connection', (socket) => {
socket.on('joinRoom', (room) => {
console.log(`Client joined room: ${room}`);
socket.join(room);
});
});
function includeRouter(folderName) {
console.log(" ======================================= ");
fs.readdirSync(folderName).forEach(function (file) {
var fullName = path.join(folderName, file);
var stat = fs.lstatSync(fullName);
if (stat.isDirectory()) {
includeRouter(fullName);
} else if (file.toLowerCase().indexOf(".js")) {
require("./" + fullName)(app);
console.log(" Found Router => '" + fullName + "'");
}
});
console.log(" ======================================= ");
}
includeRouter("app/router/");
server.listen(port, () => {
console.log(`Server running on http://localhost:${port}`);
});