-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
executable file
·51 lines (38 loc) · 1.13 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
/*
* Chat Api com NodeJs e Socket.io
* @author Miguel Carlos Honório
*/
'use strict';
const express = require("express");
const http = require('http');
const socketio = require('socket.io');
const socketEvents = require('./web/socket');
const routes = require('./web/routes');
const appConfig = require('./config/app-config');
class Server{
constructor(){
this.app = express();
this.http = http.Server(this.app);
this.socket = socketio(this.http);
}
appConfig(){
new appConfig(this.app).includeConfig();
}
/* Including app Routes starts*/
includeRoutes(){
new routes(this.app).routesConfig();
new socketEvents(this.socket).socketConfig();
}
/* Including app Routes ends*/
appExecute(){
this.appConfig();
this.includeRoutes();
const port = process.env.PORT || 4000; // comum do Socket.io
const host = process.env.HOST || `localhost`;
this.http.listen(port, host, () => {
console.log(`Listening on http://${host}:${port}`);
});
}
}
const app = new Server();
app.appExecute();