<commit_before>#!/usr/bin/env node
var configFile = process.argv[2];
var port = parseInt(process.argv[3], 10);

if (!configFile || !port) {
    console.error('Usage: bouncy [routes.json] [port]');
    process.exit(1);
}

var fs = require('fs');
var config = JSON.parse(fs.readFileSync(configFile));

var bouncy = require('bouncy');
bouncy(function (req, bounce) {
    var host = (req.headers.host || '').replace(/:\d+$/, '');
    var route = config[host] || config[''];
    
    if (Array.isArray(route)) {
        // jump to a random route on arrays
        route = route[Math.floor(Math.random() * route.length)];
    }
    
    if (typeof route === 'string') {
        var s = route.split(':');
        if (s[1]) {
            bounce(s[0], s[1]);
        }
        else {
            bounce(s);
        }
    }
    else if (route) {
        bounce(route);
    }
    else {
        var res = bounce.respond();
        res.statusCode = 404;<commit_msg>If someone makes a request with garbage, and parsing fails, the CLI tool would not catch the error and crash. That's not a nice thing to do, so now just destroy the request.<commit_after>#!/usr/bin/env node
var configFile = process.argv[2];
var port = parseInt(process.argv[3], 10);

if (!configFile || !port) {
    console.error('Usage: bouncy [routes.json] [port]');
    process.exit(1);
}

var fs = require('fs');
var config = JSON.parse(fs.readFileSync(configFile));

var bouncy = require('bouncy');
bouncy(function (req, bounce) {
    var host = (req.headers.host || '').replace(/:\d+$/, '');
    var route = config[host] || config[''];
    
    if (Array.isArray(route)) {
        // jump to a random route on arrays
        route = route[Math.floor(Math.random() * route.length)];
    }
    
    req.on('error', function(err) {
        req.destroy();
    });
    
    if (typeof route === 'string') {
        var s = route.split(':');
        if (s[1]) {
            bounce(s[0], s[1]);
        }
        else {
            bounce(s);
        }
    }
    else if (route) {
        bounce(route);
    }
    else {
        var res = bounce.respond();
        res.statusCode = 404;
{'fraction_non_alphanumeric': 0.1735266604303087, 'fraction_numerical': 0.01028999064546305, 'mean_word_length': 2.3369734789391576, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '1400044', 'n_tokens_mistral': 723, 'n_tokens_neox': 704, 'n_words': 178}