-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
54 lines (48 loc) · 1.22 KB
/
server.js
File metadata and controls
54 lines (48 loc) · 1.22 KB
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
var express = require("express");
var mysql = require("mysql");
var bodyparser = require("body-parser");
var md5 = require("md5");
var rest = require("./rest.js");
var app = express();
function REST() {
var self = this;
self.connectMyssql();
};
REST.prototype.connectMyssql = function() {
var self = this;
var pool = mysql.createPool({
connectionLimit:100,
host:'localhost',
user:'root',
password:'',
database:'login1',
debug:false
});
pool.getConnection(function (err,connection) {
if(err){
self.stop(err);
console.log(err);
}else{
self.configureExpress(connection);
}
});
}
REST.prototype.configureExpress = function (connection) {
var self=this;
app.use(bodyparser.urlencoded({extended:true}));
app.use(bodyparser.json());
var router =express.Router();
app.use('/api',router);
var rest_router=new rest(router,connection,md5);
self.startServer();
}
REST.prototype.startServer = function () {
app.listen(3000,function () {
console.log("all right i'm alive");
});
}
REST.prototype.stop = function (err) {
console.log("Issue with mysql :"+err);
process.exit(1);
};
new REST();