commonRoutes.js

var dbCollections = require('../../config/db/dbCollections');
var DashboardDemoData = require('../../constants/data/DashboardDemoData');

function commonRoutes(app, routeOptions) {
    // List of collections available
    var DB;
    if(routeOptions.database) {
        DB = dbCollections(routeOptions.database);
    }

    // GET Home Page
    app.get('/', function(req, res) {
        // sendfile is relative to app root directory
        if(process.env.NODE_ENV == 'production') {
            res.sendfile('./public/html/pages/index-cdn.html');
        }
        else {
            res.sendfile('./public/html/pages/index.html');
        }
    });

    /*app.all('*//*', function(req, res) {
        console.log("Server re-writing for angular routing");
        res.sendfile('./public/html/pages/home.html');
    });

    app.get('*', function(req, res) {
        if(isAuthenticated) res.redirect('/');
        else req.logout();
    });*/

    // Add user comment and feedback
    app.post('/api/comment/add', function(req, res) {
        var info = {
            comment: req.body.comment
        };

        console.log(req.body);

        if(DB) {
            console.log('inserting into db')
            DB.CommentClln.insert(info, function (err, data) {
                if (err) {
                    console.error(err);
                } else {
                    console.log(data);
                    res.json({
                        sucess: true
                    });
                }
            });
        }
    });

    // Get inputbox templates
    app.post('/api/inputbox/getdemodata', function(req, res) {
        res.json({
            data: DashboardDemoData
        })
    });
}

module.exports = commonRoutes;