This repository has been archived by the owner on Feb 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
66 lines (51 loc) · 1.64 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
var express = require('express');
var mysql = require('mysql');
var bodyParser = require('body-parser');
var io = require('socket.io');
var config = require('./config');
var app = express();
function API(){
var self = this;
self.connectMysql();
}
API.prototype.connectMysql = function() {
var self = this;
var pool = mysql.createPool({
connectionLimit : 100,
host : config.mysql_host,
user : config.mysql_user,
password : config.mysql_password,
database : config.mysql_database
});
pool.getConnection(function(err,connection){
if(err) {
self.stop(err);
} else {
self.configureExpress(connection);
}
});
};
API.prototype.configureExpress = function(connection) {
var self = this;
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
/* Router and route files */
var router = express.Router();
app.use('/api', router);
app.get('*', function(req, res) {
res.sendFile(__dirname + '/public/index.html');
});
var server = app.listen(config.conn_port, function(){
console.log("Eilium launched at port " + config.conn_port);
});
io = io.listen(server);
require('./api/api')(router, connection);
require('./api/users')(router, connection);
require('./api/caspar')(router, connection, io);
};
API.prototype.stop = function(err) {
console.log("An issue occurred : " + err);
process.exit(1);
};
new API();
app.use(express.static(__dirname + '/public'));