<commit_before>import http from 'http';
import https from 'https';
import express from 'express';
import mongoose from 'mongoose';
import cors from 'cors';
import bodyParser from 'body-parser';
import cookieParser from 'cookie-parser';
import fs from 'fs';
import expressValidator from 'express-validator';

import config from './config.json';

import SurveyApi from './rest-api/survey';
import QuestionApi from './rest-api/question';
import UserApi from './rest-api/user';

import SurveyService from './services/survey';
import QuestionService from './services/question';
import UserService from './services/user';

require("./telegram");
require("./facebook");
require("./messages/bot_app/models");

const hskey = fs.readFileSync('./fullchain.pem');
  const hscert = fs.readFileSync('./privkey.pem');

const serverOptions = {
  key: hskey,
  cert: hscert
};

const httpsPort = process.env.PORT || 80;
const httpPort = process.env.PORT2 || 8080;
const host = 'coinsurvey.me';

const PASSWORD = '<PASSWORD>';

const app = express();

const httpServer = http.createServer(app);
const httpsServer = https.createServer(serverOptions, app);

const corsOptions = {
    origin: ['http://localhost:3000', 'https://survey-dashboard.herokuapp.com', 'http://174.138.52.48:3000', 'http://174.138.52.48'],
    optionsSuccessStatus: 200,
    methods: 'GET,POST,PUT,DELETE',
    allowedHeaders: ['Content-Type', 'Authorization'],
    credentials: true
};


app.use(bodyParser.json({
    limit: config.bodyLimit
}));
app.use(cookieParser());

app.use(cors(corsOptions));

app.use(expressValidator({
    errorFormatter: (param, msg, value) => {
        const namespace = param.split('.');
        const root = namespace.shift();
        let formParam = root;
        
        while (namespace.length) {
            formParam += '[' + namespace.shift() + ']';
        }
        return {
            param: formParam,
            msg: msg,
            value: value
        };
    }
}));

connect()
    .on('error', console.log)
    .on('disconnected', connect)
    .once('open', listen);

function connect() {
    const options = {server: {socketOptions: {keepAlive: 1}}};
    // return mongoose.connect('mongodb://bot:<EMAIL>:45019/heroku_zlrrx207').connection;
    return mongoose.connect('mongodb://bot:bot@127.0.0.1:27017/bot').connection;
}

function listen() {
    if (app.get('env') === 'test') return;
    httpServer.listen(httpPort, host);
    httpsServer.listen(httpsPort, host);
    console.log('Express app started on ports: https - ' + httpsPort + ' and http - ' + httpPort);
}

new SurveyApi(app, new SurveyService()).register();
new QuestionApi(app, new QuestionService()).register();
new UserApi(app, new UserService()).register();

export default app;

import {botFacebook} from './facebook'

app.get('/facebook', (req, res) => {
  return botFacebook._verify(req, res)
})

app.post('/facebook', (req, res) => {
  botFacebook._handleMessage(req.body)
  res.end(JSON.stringify({status: 'ok'}))
})
<commit_msg>https test<commit_after>import http from 'http';
import https from 'https';
import express from 'express';
import mongoose from 'mongoose';
import cors from 'cors';
import bodyParser from 'body-parser';
import cookieParser from 'cookie-parser';
import fs from 'fs';
import expressValidator from 'express-validator';

import config from './config.json';

import SurveyApi from './rest-api/survey';
import QuestionApi from './rest-api/question';
import UserApi from './rest-api/user';

import SurveyService from './services/survey';
import QuestionService from './services/question';
import UserService from './services/user';

require("./telegram");
require("./facebook");
require("./messages/bot_app/models");

const hskey = fs.readFileSync('./fullchain.pem');
const hscert = fs.readFileSync('./privkey.pem');
console.log(hskey);
console.log(hscert);

const serverOptions = {
  key: hskey,
  cert: hscert
};

const httpsPort = process.env.PORT || 80;
const httpPort = process.env.PORT2 || 8080;
const host = 'coinsurvey.me';

const PASSWORD = '<PASSWORD>';

const app = express();

const httpServer = http.createServer(app);
const httpsServer = https.createServer(serverOptions, app);

const corsOptions = {
    origin: ['http://localhost:3000', 'https://survey-dashboard.herokuapp.com', 'http://172.16.17.32:3000', 'http://172.16.17.32'],
    optionsSuccessStatus: 200,
    methods: 'GET,POST,PUT,DELETE',
    allowedHeaders: ['Content-Type', 'Authorization'],
    credentials: true
};


app.use(bodyParser.json({
    limit: config.bodyLimit
}));
app.use(cookieParser());

app.use(cors(corsOptions));

app.use(expressValidator({
    errorFormatter: (param, msg, value) => {
        const namespace = param.split('.');
        const root = namespace.shift();
        let formParam = root;
        
        while (namespace.length) {
            formParam += '[' + namespace.shift() + ']';
        }
        return {
            param: formParam,
            msg: msg,
            value: value
        };
    }
}));

connect()
    .on('error', console.log)
    .on('disconnected', connect)
    .once('open', listen);

function connect() {
    const options = {server: {socketOptions: {keepAlive: 1}}};
    // return mongoose.connect('mongodb://bot:Matwey12@ds145019.mlab.com:45019/heroku_zlrrx207').connection;
    return mongoose.connect('mongodb://bot:bot@127.0.0.1:27017/bot').connection;
}

function listen() {
    if (app.get('env') === 'test') return;
    httpServer.listen(httpPort, host);
    httpsServer.listen(httpsPort, host);
    console.log('Express app started on ports: https - ' + httpsPort + ' and http - ' + httpPort);
}

new SurveyApi(app, new SurveyService()).register();
new QuestionApi(app, new QuestionService()).register();
new UserApi(app, new UserService()).register();

export default app;

import {botFacebook} from './facebook'

app.get('/facebook', (req, res) => {
  return botFacebook._verify(req, res)
})

app.post('/facebook', (req, res) => {
  botFacebook._handleMessage(req.body)
  res.end(JSON.stringify({status: 'ok'}))
})

{'fraction_non_alphanumeric': 0.16735366859027206, 'fraction_numerical': 0.020115416323165707, 'mean_word_length': 3.9317073170731707, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 12, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 7, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '597661', 'n_tokens_mistral': 1961, 'n_tokens_neox': 1882, 'n_words': 441}