<commit_before>/*
 * @author     <NAME> <<EMAIL>>
 * @copyright  2013-2018 MapCentia ApS
 * @license    http://www.gnu.org/licenses/#AGPL  GNU AFFERO GENERAL PUBLIC LICENSE 3
 */

var express = require('express');
var router = express.Router();
var configUrl = require('../config/config.js').configUrl;
var request = require('request');

router.get('/api/config/:db/:file', function (req, response) {
    var file = req.params.file, db = req.params.db, url;

    if (typeof configUrl === "object") {
        url = configUrl[db] || configUrl._default;
    } else {
        url = configUrl;
    }

    console.log(url + "/" + file);

    request.get(url + "/" + file, function (err, res, body) {

        if (err || res.statusCode !== 200) {

            response.header('content-type', 'application/json');
            response.status(400).send({
                success: false,
                message: "Could not get the requested config JSON file."
            });

            return;
        }

        response.send(JSON.parse(body));
    })
});
module.exports = router;<commit_msg>Handling of invalid JSON configs<commit_after>/*
 * @author     <NAME> <<EMAIL>>
 * @copyright  2013-2020 MapCentia ApS
 * @license    http://www.gnu.org/licenses/#AGPL  GNU AFFERO GENERAL PUBLIC LICENSE 3
 */

var express = require('express');
var router = express.Router();
var configUrl = require('../config/config.js').configUrl;
var request = require('request');

router.get('/api/config/:db/:file', function (req, response) {
    var file = req.params.file, db = req.params.db, url, json;

    if (typeof configUrl === "object") {
        url = configUrl[db] || configUrl._default;
    } else {
        url = configUrl;
    }

    console.log(url + "/" + file);

    request.get(url + "/" + file, function (err, res, body) {

        if (err || res.statusCode !== 200) {
            response.header('content-type', 'application/json');
            response.status(400).send({
                success: false,
                message: "Could not get the requested config JSON file."
            });
            return;
        }

        try {
            json = JSON.parse(body);
        } catch (e) {
            response.status(400).send({
                success: false,
                message: e.message
            });
            return;
        }
        response.send(JSON.parse(body));
    })
});
module.exports = router;
{'fraction_non_alphanumeric': 0.1551795295088733, 'fraction_numerical': 0.01361947998349154, 'mean_word_length': 2.1439688715953307, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4784220', 'n_tokens_mistral': 748, 'n_tokens_neox': 700, 'n_words': 171}