Source: config/Application.js

/// <reference path="../../typings/tsd.d.ts" />
var Express = require('express');
var DDatabase = require('./Database');
var DRouters = require('./../handlers/Routers');
var DControllers = require('./../handlers/Controllers');
var DHelpers = require('./../handlers/Helpers');
var DModels = require('./../handlers/Models');
var DMiddleware = require('./Middleware');
var IO = require('socket.io');
var http = require('http');
var helmet = require('helmet');
var passport = require('passport');
var passportHttp = require('passport-http');
var BodyParser = require('body-parser');
var CookieParser = require('cookie-parser');
var SessionParser = require('express-session');
var Dollyjs;
(function (Dollyjs) {
    /**
     * @class Application - Manage application's import
     */
    var Application = (function () {
        /**
         * @constructs Application
         */
        function Application() {
        }
        /**
         * Start the application
         * @param dollyPref {Object}
         * @static
         */
        Application.start = function (dollyPref) {
            var Middle = new DMiddleware.Middleware(Application.APP, BodyParser, CookieParser, SessionParser, passport, passportHttp, dollyPref);
            if (dollyPref.helmet.noCache) {
                Application.APP.use(helmet.noCache());
            }
            if (dollyPref.helmet.hidePoweredBy) {
                Application.APP.use(helmet.hidePoweredBy());
            }
            if (dollyPref.helmet.hpkp) {
                Application.APP.use(helmet.hpkp({ maxAge: 10886400000, sha256s: ['AbCdEf123=', 'ZyXwVu456='] }));
            }
            if (dollyPref.helmet.ieNoOpen) {
                Application.APP.use(helmet.ieNoOpen());
            }
            if (dollyPref.helmet.noSniff) {
                Application.APP.use(helmet.noSniff());
            }
            if (dollyPref.helmet.frameguard) {
                Application.APP.use(helmet.frameguard());
            }
            if (dollyPref.helmet.xssFilter) {
                Application.APP.use(helmet.xssFilter());
            }
            Application.server = http.createServer(Application.APP);
            if (dollyPref.enableIO) {
                Application.IO = IO(Application.server);
            }
            // Set up and connect to databases
            var DB = new DDatabase.Database(dollyPref);
            DB.connectDatabse();
            DB.db.sequelize.sync().then(function () {
                // Load all models
                var modelsFiles = new DModels.Models(Application.APP);
                // Load Helpers Files
                var helpersFiles = new DHelpers.Helpers(Application.APP);
                // Load all the controller files
                var controllerFiles = new DControllers.Controllers(Application.APP);
                // Load all the routers files
                var routersFiles = new DRouters.Routers(Application.APP);
                Application.PORT = dollyPref.port;
                Application.server.listen(dollyPref.port, dollyPref.ip, Application.applicationListener);
            });
        };
        /**
         * Application Listenner
         * @static
         */
        Application.applicationListener = function () {
            console.log('Running on PORT: ' + Application.PORT);
        };
        /**
         * @static Intialize the express Application
         * @type any
         */
        Application.APP = Express();
        /**
         * Application post
         * @type {any|number}
         */
        Application.PORT = process.env.PORT || 3000;
        return Application;
    })();
    Dollyjs.Application = Application;
})(Dollyjs || (Dollyjs = {}));
module.exports = Dollyjs;
//# sourceMappingURL=Application.js.map