-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
50 lines (40 loc) · 1.54 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
/*=====================Initialisation=====================*/
const express = require("express");
require('dotenv').config();
const app = express();
const http = require('http').Server(app);
const io = require('socket.io')(http);
const fs = require('fs');
const bodyParser = require('body-parser')
const path = require('path');
const minify = require('express-minify');
/*======================================================*/
// Middleware session
app.use(minify({cache: __dirname + '/cache'}));
app.use(bodyParser.json({limit: '10MB'})); // to support JSON-encoded bodies
app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
extended: true
}));
/*======================routes==========================*/
app.get('/game/:id', function(req, res) {
res.sendFile(__dirname + "/public/view/game.html")
});
app.get('/', function(req, res) {
res.sendFile(__dirname + "/public/view/index.html")
});
app.get('/api/game/data', function(req, res) {
res.sendFile(__dirname + "/config/game.json")
});
/*======================route fichier static (public)====================*/
app.use("/css", express.static(__dirname + '/public/css'));
app.use("/img", express.static(__dirname + '/public/img'));
app.use("/js", express.static(__dirname + '/public/js'));
/*==================start serv==================*/
http.listen(process.env.PORT, function(){
console.log('listening on *:' + process.env.PORT);
});
io.on('connection', (socket) => {
socket.roomslist = [];
require('./src/gameManager.js')(socket, io);
require('./src/chat.js')(socket, io);
});