/*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
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;