<commit_before>var fs = require('fs');
var https = require('https');
var express = require('express');
var helmet = require('helmet');
var Moonboots = require('moonboots');
var config = require('getconfig');
var templatizer = require('templatizer');
var oembed = require('oembed');
var async = require('async');


var app = express();

app.use(express.compress());
app.use(express.static(__dirname + '/public'));
if (!config.isDev) {
    app.use(helmet.xframe());
}
app.use(helmet.iexss());
app.use(helmet.contentTypeOptions());

oembed.EMBEDLY_URL = config.embedly.url || 'https://api.embed.ly/1/oembed';
oembed.EMBEDLY_KEY = config.embedly.key;

var clientApp = new Moonboots({
    main: __dirname + '/clientapp/app.js',
    templateFile: __dirname + '/clientapp/templates/main.html',
    developmentMode: config.isDev,
    cachePeriod: 0,
    libraries: [
        __dirname + '/clientapp/libraries/jquery.js',
        __dirname + '/clientapp/libraries/ui.js',
        __dirname + '/clientapp/libraries/resampler.js',
        __dirname + '/clientapp/libraries/IndexedDBShim.min.js',
        __dirname + '/clientapp/libraries/sugar-1.2.1-dates.js'
    ],
    browserify: {
        debug: false
    },
    stylesheets: [
        __dirname + '/public/css/otalk.css'
    ],
    server: app
});

if (config.isDev) {
    clientApp.config.beforeBuildJS = function () {
        var clientFolder = __dirname + '/clientapp';
        templatizer(clientFolder + '/templates', clientFolder + '/templates.js');
    };
}

clientApp.on('ready', function () {
    console.log('Client app ready');
    var pkginfo = JSON.parse(fs.readFileSync(__dirname + '/package.json'));

    var manifestTemplate = fs.readFileSync(__dirname + '/clientapp/templates/misc/manifest.cache', 'utf-8');
    var cacheManifest = manifestTemplate
          .replace('#{version}', pkginfo.version + config.isDev ? ' ' + Date.now() : '')
          .replace('#{jsFileName}', clientApp.jsFileName())
          .replace('#{cssFileName}', clientApp.cssFileName());
    console.log('Cache manifest generated');


    app.get('/manifest.cache', function (req, res, next) {
        res.set('Content-Type', 'text/cache-manifest');
        res.set('Cache-Control', 'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0');
        res.send(cacheManifest);
    });

    // serves app on every other url
    app.get('*', clientApp.html());
});

var webappManifest = fs.readFileSync('./public/x-manifest.webapp');

app.set('view engine', 'jade');

app.get('/login', function (req, res) {
    res.render("login", {"config": config.server});
});

app.get('/logout', function (req, res) {
    res.render('logout');
});

app.get('/config.js', function (req, res) {
    res.send("var SERVER_CONFIG = " + JSON.stringify(config.server) + ";");
});

app.get('/oauth/login', function (req, res) {
    res.redirect('https://apps.andyet.com/oauth/authorize?client_id=' + config.andyetAuth.id + '&response_type=token');
});

app.get('/oauth/callback', function (req, res) {
    res.render('oauthLogin');
});

app.get('/manifest.webapp', function (req, res, next) {
    res.set('Content-Type', 'application/x-web-app-manifest+json');
    res.send(webappManifest);
});

app.get('/oembed', function (req, res) {
    var callback = req.query.callback;
    if (req.query.url) {
        oembed.fetch(req.query.url, req.query, function (err, result) {
            if (err || !result) {
                return res.status(500).send();
            }
            res.status(200);
            res.set('Content-Type', oembed.MIME_OEMBED_JSON);
            if (callback) {
                res.send(callback + '(' + JSON.stringify(result) + ')');
            } else {
                res.send(JSON.stringify(result));
            }
        });<commit_msg>Fix: config JSON file MIME type<commit_after>var fs = require('fs');
var https = require('https');
var express = require('express');
var helmet = require('helmet');
var Moonboots = require('moonboots');
var config = require('getconfig');
var templatizer = require('templatizer');
var oembed = require('oembed');
var async = require('async');


var app = express();

app.use(express.compress());
app.use(express.static(__dirname + '/public'));
if (!config.isDev) {
    app.use(helmet.xframe());
}
app.use(helmet.iexss());
app.use(helmet.contentTypeOptions());

oembed.EMBEDLY_URL = config.embedly.url || 'https://api.embed.ly/1/oembed';
oembed.EMBEDLY_KEY = config.embedly.key;

var clientApp = new Moonboots({
    main: __dirname + '/clientapp/app.js',
    templateFile: __dirname + '/clientapp/templates/main.html',
    developmentMode: config.isDev,
    cachePeriod: 0,
    libraries: [
        __dirname + '/clientapp/libraries/jquery.js',
        __dirname + '/clientapp/libraries/ui.js',
        __dirname + '/clientapp/libraries/resampler.js',
        __dirname + '/clientapp/libraries/IndexedDBShim.min.js',
        __dirname + '/clientapp/libraries/sugar-1.2.1-dates.js'
    ],
    browserify: {
        debug: false
    },
    stylesheets: [
        __dirname + '/public/css/otalk.css'
    ],
    server: app
});

if (config.isDev) {
    clientApp.config.beforeBuildJS = function () {
        var clientFolder = __dirname + '/clientapp';
        templatizer(clientFolder + '/templates', clientFolder + '/templates.js');
    };
}

clientApp.on('ready', function () {
    console.log('Client app ready');
    var pkginfo = JSON.parse(fs.readFileSync(__dirname + '/package.json'));

    var manifestTemplate = fs.readFileSync(__dirname + '/clientapp/templates/misc/manifest.cache', 'utf-8');
    var cacheManifest = manifestTemplate
          .replace('#{version}', pkginfo.version + config.isDev ? ' ' + Date.now() : '')
          .replace('#{jsFileName}', clientApp.jsFileName())
          .replace('#{cssFileName}', clientApp.cssFileName());
    console.log('Cache manifest generated');


    app.get('/manifest.cache', function (req, res, next) {
        res.set('Content-Type', 'text/cache-manifest');
        res.set('Cache-Control', 'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0');
        res.send(cacheManifest);
    });

    // serves app on every other url
    app.get('*', clientApp.html());
});

var webappManifest = fs.readFileSync('./public/x-manifest.webapp');

app.set('view engine', 'jade');

app.get('/login', function (req, res) {
    res.render("login", {"config": config.server});
});

app.get('/logout', function (req, res) {
    res.render('logout');
});

app.get('/config.js', function (req, res) {
    res.type('application/javascript');
    res.send("var SERVER_CONFIG = " + JSON.stringify(config.server) + ";");
});

app.get('/oauth/login', function (req, res) {
    res.redirect('https://apps.andyet.com/oauth/authorize?client_id=' + config.andyetAuth.id + '&response_type=token');
});

app.get('/oauth/callback', function (req, res) {
    res.render('oauthLogin');
});

app.get('/manifest.webapp', function (req, res, next) {
    res.set('Content-Type', 'application/x-web-app-manifest+json');
    res.send(webappManifest);
});

app.get('/oembed', function (req, res) {
    var callback = req.query.callback;
    if (req.query.url) {
        oembed.fetch(req.query.url, req.query, function (err, result) {
            if (err || !result) {
                return res.status(500).send();
            }
            res.status(200);
            res.set('Content-Type', oembed.MIME_OEMBED_JSON);
            if (callback) {
                res.send(callback + '(' + JSON.stringify(result) + ')');
            } else {
                res.send(JSON.stringify(result));
            }
        });
{'fraction_non_alphanumeric': 0.1830031282586027, 'fraction_numerical': 0.003910323253388947, 'mean_word_length': 3.1997810618500275, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, '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': '3537887', 'n_tokens_mistral': 2494, 'n_tokens_neox': 2467, 'n_words': 432}