This repository has been archived by the owner on Jun 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
executable file
·81 lines (61 loc) · 1.82 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Imports
const express = require('express');
const app = express();
const server = require('http').Server(app);
const io = require('socket.io')(server);
const compression = require('compression');
const minify = require('express-minify');
//const RateLimit = require('express-rate-limit');
const port = 6969;
/*const limiter = new RateLimit({
windowMs: 1 * 60 * 1000,
max: 50
});*/
//const router = express.Router();
// apply rate limiter to all requests
//router.use(limiter);
//router.use(express.static('public'));
app.use(compression());
app.use(minify());
app.use(express.static('public'));
// API Routes
app.get('/', (req, res) => {
res.sendFile('public/templates/splash.html', { root: __dirname });
});
app.get('/chat', (req, res) => {
res.sendFile('public/templates/client_chat.html', { root: __dirname });
});
// Legal
app.get('/legal', (req, res) => {
res.sendFile('public/templates/legal.html', { root: __dirname });
});
app.get('/terms', (req, res) => {
res.sendFile('public/templates/terms.html', { root: __dirname });
});
app.get('/privacy', (req, res) => {
res.sendFile('public/templates/privacy.html', { root: __dirname });
});
//The 404 Route (ALWAYS Keep this as the last route)
app.get('*', function(req, res){
res.status(404).sendFile('public/templates/404.html', { root: __dirname });
});
// SocketIO
io.on('connection', (connection) => {
connection.on('chat event', (data) => {
try {
JSON.parse(x);
} catch (e) {
json = false
}
if (typeof data === 'object' || json == true) {
io.emit('my response', data);
return
}
console.log("Event was rejected." + data)
});
});
// Server start
//app.use('/', router)
server.listen(port, () => {
console.log('listening on *:' + port);
});