-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
68049a2
commit 367e81a
Showing
1 changed file
with
53 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,53 @@ | ||
var express=require("express"); | ||
var mysql=require("mysql"); | ||
var bodyparser=require("body-parser"); | ||
|
||
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 =expres.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); | ||
}; |