-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
81 lines (70 loc) · 1.8 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
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
'use strict';
/**
* Module dependencies.
*/
const express = require('express');
const helmet = require('helmet');
const nocache = require('nocache');
const compression = require('compression');
const path = require('path');
const dotenv = require('dotenv');
const favicon = require('serve-favicon');
const errorHandler = require('errorhandler');
/**
* import Server Game
*/
const Game = require('./app/server.js');
const logger = require('./app/logger.js');
/**
* Load environment variables from .env file.
*/
dotenv.load({path: '.env'});
/**
* Create Express server.
*/
const app = express();
const server = require('http').createServer(app);
const io = require('socket.io')(server);
const port = process.env.PORT || 8080;
/**
* Express configuration.
*/
app.use(helmet());
app.use(compression());
app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
if (process.env.NODE_ENV === 'development') {
app.use(nocache()); // only use in development
}
/**
* Socket
*/
server.listen(port, () => {
logger.log('info', `
___ ____ _ _ _ ___ ___
|_ _| _ \\ / \\ | \\ | |_ _/ _ \\
| || | | |/ _ \\ | \\| || | | | |
| || |_| / ___ \\| |\\ || | |_| |
|___|____/_/ \\_\\_| \\_|___\\___/
✓ App is running at http://localhost:${port} in ${app.get('env')} mode.
Command line arguments: ${process.argv.slice(2)}
`);
});
/**
* Basic Routing.
*/
app.use(express.static(path.join(__dirname, 'public'), {maxAge: 31557600000}));
/**
* Constructing a Server Game instance, and start server game clock.
* @type {Server}
*/
const game = new Game(io);
game.setup(process.argv.slice(2));
game.start();
/**
* Error Handler.
*/
if (process.env.NODE_ENV === 'development') {
// only use in development
app.use(errorHandler());
}
module.exports = app;