{"size": 1239, "ext": "js", "max_stars_repo_path": "deploy/logserver/server.js", "max_stars_repo_name": "kenmcmil/minq", "max_stars_repo_stars_event_min_datetime": "2021-07-15T01:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-15T01:48:11.000Z", "max_issues_repo_path": "deploy/logserver/server.js", "max_issues_repo_name": "enzoh/minq", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "deploy/logserver/server.js", "max_forks_repo_name": "enzoh/minq", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.3773584906, "max_line_length": 71, "alphanum_fraction": 0.5536723164}
var express = require('express');
var fs = require('fs');
var readline = require('readline');
var connid_regex = /[0-9a-fA-F]+$/;

var app = express();

var port = process.env.PORT || 3000;

if (process.argv.len < 2) {
    console.log("Need to specify log file");
    return;
}
var file = process.argv[2];
console.log(file);

app.get('/:connid', function(request, response) {
    var connid = request.params.connid;
    if (!connid.match(connid_regex)) {
        response.status(400).send("Bogus connid (non-hex characters)");
        return;
    }

    if(connid.length != 16) {
        response.status(400).send("Bogus connid (wrong length)");
        return;
    }

    connid = connid.toLowerCase();
    
    var match = 'Conn: ' + connid + ":";
    var data = "<pre>";
    const rl = readline.createInterface({
        input: fs.createReadStream(file),
        terminal: false
    });
    rl.on('line', function(l) {
        if (l.search(match) != -1) {
            data += l;
            data += "\n";
        }
    });
    rl.on('close', function() {
        data += "</pre>";
        response.send(data);
    });
});

app.listen(port, function() {
    console.log("Listening on " + port);
    console.log("Logfile = " + file);
});
