-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
47 lines (39 loc) · 1.27 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
const app = require('express')();
const http = require('http').Server(app);
const io = require('socket.io')(http);
const RestFulApiMiddleware = require('./middlewares/RestFulApiMiddleware');
const mysqlDB = require('./database/mysqlDB');
const MysqlController = require('./controllers/MysqlController');
const SocketServer = require('./socketServer');
module.exports = class App {
constructor(port) {
this.http = http;
this.app = app
this.io = io
this.port = process.env.PORT || port;
}
async mountDatabase() {
await mysqlDB.mount();
}
mountMiddleware() {
RestFulApiMiddleware.inCludeApp(this.app);
RestFulApiMiddleware.mount();
}
mountSocketServer() {
const socketServer = new SocketServer(this.io);
socketServer.mount();
}
mountController() {
MysqlController.inCludeApp(this.app, this.io);
MysqlController.mount();
}
async start() {
await this.mountMiddleware();
await this.mountDatabase();
await this.mountSocketServer();
await this.mountController();
this.http.listen(this.port, () => {
console.log('\x1b[31m', 'System:', '\x1b[37m', `Server Start on port \x1b[32m${this.port}\x1b[37m`)
})
}
}