<commit_before>/*
#     CloudBoost - Core Engine that powers Bakend as a Service
#     (c) 2014 HackerBay, Inc.
#     CloudBoost may be freely distributed under the Apache 2 License
*/

global.env = process.env.NODE_ENV || 'development';

global.express = require('express');
global.request = require('request');
var pjson = require('./package.json');
var fs = require('fs');
global.rootPath = require('app-root-path');
var busboyBodyParser = require('busboy-body-parser');
var q = require("q");
var _ = require('underscore');
var path = require('path');

global.mongoDisconnected = false;
global.winston = require('winston');
expressWinston = require('express-winston');
require('winston-loggly');
var slack = require('winston-bishop-slack').Slack;
var util = require('util');

var CLOUDBOOST_HOSTED = process.env["CLOUDBOOST_HOSTED"]
console.log('IS CLOUDBOOST RUNNING ON AN HOSTED ENV - ' , CLOUDBOOST_HOSTED)

global.keys = require('./database-connect/keys.js')();

if (global.env === "development") {
    //Loggly Development Keys
    global.keys.logToken = "f0ebeed1-6c71-47b8-9014-e9ca69a2b114";
    global.keys.logglySubDomain = "cloudboostdev";
}

global.winston.add(global.winston.transports.Loggly, {
    inputToken: global.keys.logToken,
    subdomain: global.keys.logglySubDomain,
    tags: ["cloudboost-server"],
    json: true
});

// add slack transport if API key found
if(global.keys.slackWebHook){
    var envVal = process.env["IS_STAGING"] ? 'STAGING' : 'PRODUCTION'
    global.winston.add(slack, {
        webhook_url: global.keys.slackWebHook,
        icon_url: "https://cdn2.iconfinder.com/data/icons/circle-icons-1/64/caution-128.png",
        channel: "#devlogs",
        username: "API ERROR BOT - " + envVal,
        level: 'error',
        handleExceptions: true,
        customFormatter: function(level, message, meta) {
            return { attachments: [ {
            fallback: "An Error occured on API POD in - " + envVal,
            pretext: "An Error occured on API POD in - " + envVal,
            color: '#D00000',
            fields: [{
                    title: meta.error,
                    value: meta.stack,
                    short: false
                }]
            }]}
        }
    })
}

global.keyService = require('./database-connect/keyService.js');

global.q = require('q');
global.uuid = require('uuid');
var bodyParser = require('body-parser');
var session = require('express-session');
global.app = global.express();

//For pages in cloudboost
global.app.set('view engine', 'ejs');
global.app.use('*/assets',global.express.static(path.join(__dirname, 'page-templates/assets')));
global.app.use(bodyParser.json({limit: '5mb'}));
global.app.use(bodyParser.urlencoded({limit: '5mb'}));

var http = null;
var https = null;
try {
    if (fs.statSync('./config/cert.crt').isFile() && fs.statSync('./config/key.key').isFile()) {
        //use https
        console.log("Found HTTPS Certs, adding to https server.");
        var httpsOptions = {
            key: fs.readFileSync('./config/key.key'),
            cert: fs.readFileSync('./config/cert.crt')
        };
        https = require('https').Server(httpsOptions, global.app);

    }
} catch (e) {
    console.log("INFO : SSL Certificate not found or is invalid.");
    console.log("Switching ONLY to HTTP...");
}

http = require('http').createServer(global.app);

require('./database-connect/cors.js')(); //cors!
var io = require('socket.io')();

// attach io to https only if running in hosted env and certs are found
if (https && CLOUDBOOST_HOSTED) {
    io.attach(https);
} else {
    io.attach(http);
}

var Redis = require('ioredis');

var ioRedisAdapter = require('socket.io-redis');

global.sessionHelper = require('./helpers/session.js');
global.socketSessionHelper = require('./helpers/socketSession.js');
global.socketQueryHelper = require('./helpers/socketQuery.js');
global.cloudBoostHelper = require('./helpers/cloudboost.js')();
global.aclHelper = require('./helpers/ACL.js');
<commit_msg>enable both http and https at same time<commit_after>/*
#     CloudBoost - Core Engine that powers Bakend as a Service
#     (c) 2014 HackerBay, Inc.
#     CloudBoost may be freely distributed under the Apache 2 License
*/

global.env = process.env.NODE_ENV || 'development';

global.express = require('express');
global.request = require('request');
var pjson = require('./package.json');
var fs = require('fs');
global.rootPath = require('app-root-path');
var busboyBodyParser = require('busboy-body-parser');
var q = require("q");
var _ = require('underscore');
var path = require('path');

global.mongoDisconnected = false;
global.winston = require('winston');
expressWinston = require('express-winston');
require('winston-loggly');
var slack = require('winston-bishop-slack').Slack;
var util = require('util');

var CLOUDBOOST_HOSTED = process.env["CLOUDBOOST_HOSTED"]
console.log('IS CLOUDBOOST RUNNING ON AN HOSTED ENV - ' , CLOUDBOOST_HOSTED)

global.keys = require('./database-connect/keys.js')();

if (global.env === "development") {
    //Loggly Development Keys
    global.keys.logToken = "f0ebeed1-6c71-47b8-9014-e9ca69a2b114";
    global.keys.logglySubDomain = "cloudboostdev";
}

global.winston.add(global.winston.transports.Loggly, {
    inputToken: global.keys.logToken,
    subdomain: global.keys.logglySubDomain,
    tags: ["cloudboost-server"],
    json: true
});

// add slack transport if API key found
if(global.keys.slackWebHook){
    var envVal = process.env["IS_STAGING"] ? 'STAGING' : 'PRODUCTION'
    global.winston.add(slack, {
        webhook_url: global.keys.slackWebHook,
        icon_url: "https://cdn2.iconfinder.com/data/icons/circle-icons-1/64/caution-128.png",
        channel: "#devlogs",
        username: "API ERROR BOT - " + envVal,
        level: 'error',
        handleExceptions: true,
        customFormatter: function(level, message, meta) {
            return { attachments: [ {
            fallback: "An Error occured on API POD in - " + envVal,
            pretext: "An Error occured on API POD in - " + envVal,
            color: '#D00000',
            fields: [{
                    title: meta.error,
                    value: meta.stack,
                    short: false
                }]
            }]}
        }
    })
}

global.keyService = require('./database-connect/keyService.js');

global.q = require('q');
global.uuid = require('uuid');
var bodyParser = require('body-parser');
var session = require('express-session');
global.app = global.express();

//For pages in cloudboost
global.app.set('view engine', 'ejs');
global.app.use('*/assets',global.express.static(path.join(__dirname, 'page-templates/assets')));
global.app.use(bodyParser.json({limit: '5mb'}));
global.app.use(bodyParser.urlencoded({limit: '5mb'}));

var http = null;
var https = null;
try {
    if (fs.statSync('./config/cert.crt').isFile() && fs.statSync('./config/key.key').isFile()) {
        //use https
        console.log("Found HTTPS Certs, adding to https server.");
        var httpsOptions = {
            key: fs.readFileSync('./config/key.key'),
            cert: fs.readFileSync('./config/cert.crt')
        };
        https = require('https').Server(httpsOptions, global.app);

    }
} catch (e) {
    console.log("INFO : SSL Certificate not found or is invalid.");
    console.log("Switching ONLY to HTTP...");
}

http = require('http').createServer(global.app);

require('./database-connect/cors.js')(); //cors!
var io = require('socket.io')();

io.attach(http);
// attach io to https, only if running in hosted env and certs are found
if (https && CLOUDBOOST_HOSTED) {
    io.attach(https);
}


var Redis = require('ioredis');

var ioRedisAdapter = require('socket.io-redis');

global.sessionHelper = require('./helpers/session.js');
global.socketSessionHelper = require('./helpers/socketSession.js');
global.socketQueryHelper = require('./helpers/socketQuery.js');
global.cloudBoostHelper = require('./helpers/cloudboost.js')();
global.aclHelper = require('./helpers/ACL.js');

{'fraction_non_alphanumeric': 0.16129834597686854, 'fraction_numerical': 0.009451560751150355, 'mean_word_length': 3.3706521739130433, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '439059', 'n_tokens_mistral': 2609, 'n_tokens_neox': 2511, 'n_words': 544}