This repository has been archived by the owner on Jan 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
70 lines (57 loc) · 1.49 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
70
/**
* Created by davedega on 13/12/16.
*/
var db = require('./db/db.js');
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(function (req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Content-Type', 'application/json');
res.header('Access-Control-Allow-Headers', 'skip, limit');
next();
});
/**
* The domain in which the server will be anwsering.
* */
var SERVER_NAME = "localhost";
/**
* The port in which the server will be anwsering.
* */
var PORT = 4000;
var connection = {
host: 'localhost',
user: 'davedega',
password: 'dav3d3ga',
database: 'valparaiso'
};
db.sayhello();
db.connect(getDbConf(), function (err) {
(err) ? error(err) : success(app);
})
// connection.connect(function (err) {
// (err) ? error(err) : success(app);
// });
function error(err) {
console.log('Unable to connect to Mysql. ' + err);
process.exit(1);
}
function success(app) {
console.log('Connected to "' + connection.database + '"');
app.listen(PORT, SERVER_NAME, function () {
console.log("Listening on port " + PORT);
require('./routes/routes.js')(app);
});
// Logger.setLevel(LOG_LEVEL);
}
function getDbConf() {
return {
connectionLimit: 10,
host: 'localhost',
user: 'davedega',
password: 'dav3d3ga',
database: 'valparaiso'
}
}