Parent: [959c04] (diff)

Child: [798bd2] (diff)

Download this file

server.js    92 lines (74 with data), 3.1 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*made by Miguel Rodrigues @ KBZ miguel.rodrigues@knowledgebiz.pt*/
//Start Server (npm start)
// modules =================================================
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var constants = require('../constants.js');
var methodOverride = require('method-override');
var mysql = require('mysql');
var logger = require('../config/logger.js');
// Notification ===========================================
// config files
var db = require('../config/db');
/*
//Environment Variables
console.log("Environment Variables:");
console.log("******************************************************");
console.log("Using port: " + process.env.PORT);
console.log("Using User Email: " + process.env.USEREMAIL);
console.log("Using User Password: " + process.env.USERPWD);
console.log("Using DB User: " + process.env.DBUSER);
console.log("Using DB Password: " + process.env.DBPASSWORD);
console.log("Using DB Database: " + process.env.DATABASE);
console.log("******************************************************");
*/
//Environment Variables
logger.info("Environment Variables:");
logger.info("******************************************************");
logger.info("Using port: " + process.env.PORT);
logger.info("Using User Email: " + process.env.USEREMAIL);
logger.info("Using User Password: " + process.env.USERPWD);
logger.info("Using DB User: " + process.env.DBUSER);
logger.info("Using DB Password: " + process.env.DBPASSWORD);
logger.info("Using DB Database: " + process.env.DATABASE);
logger.info("******************************************************");
// set our port
var port = process.env.PORT || 8000;
// connect to our MySQL database
logger.info("MySQL Trying to connect...");
try {
var con = mysql.createConnection({
host: db.host,
user: db.user,
password: db.password,
database: db.database
});
con.connect(function(err) {
if (err) throw err;
logger.info("MySQL connected Successful!!");
});
}catch(e){
logger.error("MySQL error: ", e.stack);
}
exports = module.exports = con;
// get all data/stuff of the body (POST) parameters
// parse application/json
app.use(bodyParser.json());
// parse application/vnd.api+json as json
app.use(bodyParser.json({ type: 'application/vnd.api+json' }));
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: true }));
// override with the X-HTTP-Method-Override header in the request. simulate DELETE/PUT
app.use(methodOverride('X-HTTP-Method-Override'));
// set the static files location /public/img will be /img for users
app.use(express.static(constants.FRONTEND_PATH + '/public'));
// routes ==================================================
require('./routes')(app); // configure our routes
// start app ===============================================
// startup our app at http://localhost:3000
app.listen(port);
logger.info("Notification Enabler is running at port", port);
//console.log("Notification Enabler is running at port", port);
// expose app
exports = module.exports = app;