<commit_before>const express = require('express');
const compression = require('compression');
const path = require('path');
const request = require('request');
const parser = require('body-parser');
const dbHelper = require('./modules/database-helper');
const firebaseHelper = require('./modules/firebase-helper');

const app = express();

const PORT = process.env.PORT || 3000;
const XKCD = 'http://xkcd.com/';

var db;

app.use(compression());
app.use(parser.json());
app.use(parser.urlencoded({
    extended: true
}));
app.use(express.static(path.join(__dirname + '/static')));
app.use(express.static(path.join(__dirname + '/../dist')));
app.use(express.static(path.join(__dirname + '/..')));

app.get('/', (req, res) => {
    res.sendFile(path.join(__dirname + '/../dist/index.html'));
});

app.get('/latest', (req, res) => {
    request(`${XKCD}info.0.json`, (err, response, body) => {
        if (!err && response.statusCode === 200) {
            res.json(body);
        } else {
            console.error(err);
            res
                .status(500)
                .send('Failure : ' + err);
        }
    });
});

app.get('/all', (req, res) => {
    dbHelper.getAllPosts(db)<commit_msg>Add http to https redirect<commit_after>const express = require('express');
const compression = require('compression');
const path = require('path');
const request = require('request');
const parser = require('body-parser');
const dbHelper = require('./modules/database-helper');
const firebaseHelper = require('./modules/firebase-helper');

const app = express();
const env = process.env.NODE_ENV || 'development';
const PORT = process.env.PORT || 3000;
const XKCD = 'http://xkcd.com/';

var db;

if (env === 'production') {
    app.use(function forceSSL(req, res, next) {
        if (req.headers['x-forwarded-proto'] !== 'https') {
            return res.redirect(['https://', req.get('Host'), req.url].join(''));
        }
        return next();
    });
}
app.use(compression());
app.use(parser.json());
app.use(parser.urlencoded({
    extended: true
}));
app.use(express.static(path.join(__dirname + '/static')));
app.use(express.static(path.join(__dirname + '/../dist')));
app.use(express.static(path.join(__dirname + '/..')));

app.get('/', (req, res) => {
    res.sendFile(path.join(__dirname + '/../dist/index.html'));
});

app.get('/latest', (req, res) => {
    request(`${XKCD}info.0.json`, (err, response, body) => {
        if (!err && response.statusCode === 200) {
            res.json(body);
        } else {
            console.error(err);
            res
                .status(500)
                .send('Failure : ' + err);
        }
    });
});

app.get('/all', (req, res) => {
    dbHelper.getAllPosts(db)
{'fraction_non_alphanumeric': 0.21318681318681318, 'fraction_numerical': 0.00805860805860806, 'mean_word_length': 3.150455927051672, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '563305', 'n_tokens_mistral': 884, 'n_tokens_neox': 857, 'n_words': 163}