forked from tcoupin/mots
-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
69 lines (52 loc) · 1.88 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
/**
* Module dependencies.
*/
var express = require('express'),
routes = require('./routes'),
http = require('http'),
path = require('path'),
app = express(),
config = require('./conf.json'),
mfl = require('./game_files/motsFleches'),
favicon = require('serve-favicon'),
methodOverride = require('method-override'),
errorhandler = require('errorhandler'),
_gridNumber = 0;
const PORT = process.env.PORT || 3000
// all environments
app.set('port', PORT);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(favicon(path.join(__dirname, 'public', 'images', 'favicon.ico')));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(methodOverride());
app.use(express.static(path.join(__dirname, 'public')));
// development only
if ('development' == app.get('env')) {
app.use(errorhandler());
}
app.get('/', routes.index);
app.get('/conf.json', function(req, res) {
res.json({ SOCKET_ADDR: config.SOCKET_ADDR, SOCKET_PORT: config.SOCKET_PORT });
});
// Start server
var server = http.createServer(app);
// Retreive command line arguments
if (process.argv[2]) {
// If the user wants the default grid (debug purpose)
if ((isNaN(process.argv[2])) && (process.argv[2].toLowerCase() == 'default'))
_gridNumber = -1;
// Else if the user try to retreive a special grid
else if (!isNaN(process.argv[2]))
_gridNumber = process.argv[2];
}
mfl.startMflServer(server, _gridNumber);
server.listen(app.get('port'), onServerReady);
/** Call when the express server has started */
async function onServerReady() {
console.log('Express server listening on port ' + app.get('port'));
console.log(`\n\n\tWaiting for players at ${config.SOCKET_ADDR}:${PORT}\n\n`);
// Load desired grid in parameter.
// -1 to retreive the day grid, 0 for the default one or any number for a special one
}