-
Notifications
You must be signed in to change notification settings - Fork 1
/
server_old.js
59 lines (49 loc) · 1.75 KB
/
server_old.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
/**
* Created by Adjo Abigail YETE
* on 3/18/19.
*/
const express = require('express'),
app = express(),
bodyParser = require('body-parser');
port = process.env.PORT || 3300; //3000
const mysql = require('mysql');
// connection configurations
const mc = mysql.createConnection({
host : '185.74.71.245',
user : 'root',
port : '3306',
password : 'EYGtpv96362',
database : 'nesz_postecash'
});
// connect to database
mc.connect();
handleDisconnect(mc);
function handleDisconnect(client) {
client.on('error', function (error) {
if (!error.fatal) return;
if (error.code !== 'PROTOCOL_CONNECTION_LOST') throw err;
console.error('> Re-connecting lost MySQL connection: ' + error.stack);
// NOTE: This assignment is to a variable from an outer scope; this is extremely important
// If this said `client =` it wouldn't do what you want. The assignment here is implicitly changed
// to `global.mysqlClient =` in node.
mysqlClient = mysql.createConnection(client.config);
handleDisconnect(mysqlClient);
mysqlClient.connect();
});
};
app.listen(port);
console.log('API server started on: ' + port);
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.all('/*', function(request, response, next) {
response.header("Access-Control-Allow-Origin", "*");
response.header('Access-Control-Allow-Methods', 'GET, PUT, POST, DELETE, OPTIONS');
response.header('Access-Control-Allow-Headers', 'Origin, Content-Type, Accept');
if (request.method == 'OPTIONS') {
response.status(200).end();
} else {
next();
}
});
var routes = require('./app/routes/appRoutes'); //importing route
routes(app); //register the route