<commit_before>var finalHandler = require('finalhandler'),
    serveStatic = require('serve-static'),
    serve = serveStatic(__dirname + '/../static', {
        'index': ['landing_page.html', 'index.html']
    }),
    fs = require('fs'),
    path = require('path');

var RequestRouter = function() {

    var handleGet = function(req, res) {
        var done = finalHandler(res, res);
        serve(req, res, done);
    };

    var handlePost = function(req, res) {
        var formidable = require('formidable'),
            uploadDir = __dirname + '/../run/',
            util = require('util'),
            form = new formidable.IncomingForm();

        form.uploadDir = uploadDir;

        form.parse(req, function(err, fields, files) {
            var tempFile = files.file,
                newFileName = 'upload_' + new Date().getTime().toString() + path.extname(tempFile.name);

            fs.rename(tempFile.path, path.join(uploadDir, newFileName), function(err) {
                console.log(err);
            });

            responses = sendMessages(path.join(uploadDir, newFileName));
            console.log(JSON.stringify(responses));

            res.writeHead(302, {
                'content-type': 'text/html',
                'Location': req.url,
                'Set-Cookie': JSON.stringify(responses)
            });

            res.end();
        });
    };

    var handleProhibitted = function(req, res) {
        res.writeHead(403, {
            'Content-type': 'text/plain'
        });
        res.write('Request not permitted');
        res.end();
    };

    var sendMessages = function(filePath){
        var rapidProresponses = []
        Case = require('./case');

        Case.load(filePath).then(function (allCases) {
            var rapidProMessages = allCases.map(function (aCase) {
                return aCase.toRapidProMessage();
            });

            rapidProMessages.forEach(function (message) {
                message.send().then(function(responseBody) {
                    console.log(responseBody);
                });
            });
        });
        return rapidProresponses;
    };

    this.handle = function(req, res) {
        if (req.method == 'GET') {
            handleGet(req, res);
        } else if (req.method == 'POST') {
            handlePost(req, res);
        } else {
            handleProhibitted(req, res);
        }
    };
};<commit_msg>Fixme ... to resolve the promises<commit_after>var finalHandler = require('finalhandler'),
    serveStatic = require('serve-static'),
    serve = serveStatic(__dirname + '/../static', {
        'index': ['landing_page.html', 'index.html']
    }),
    fs = require('fs'),
    path = require('path');

var RequestRouter = function() {

    var handleGet = function(req, res) {
        var done = finalHandler(res, res);
        serve(req, res, done);
    };

    var handlePost = function(req, res) {
        var formidable = require('formidable'),
            uploadDir = __dirname + '/../run/',
            util = require('util'),
            form = new formidable.IncomingForm();

        form.uploadDir = uploadDir;

        form.parse(req, function(err, fields, files) {
            var tempFile = files.file,
                newFileName = 'upload_' + new Date().getTime().toString() + path.extname(tempFile.name);

            fs.rename(tempFile.path, path.join(uploadDir, newFileName), function(err) {
                console.log(err);
            });

            responses = sendMessages(path.join(uploadDir, newFileName));
            console.log(JSON.stringify(responses));

            res.writeHead(302, {
                'content-type': 'text/html',
                'Location': req.url,
                'Set-Cookie': JSON.stringify(responses)
            });

            res.end();
        });
    };

    var handleProhibitted = function(req, res) {
        res.writeHead(403, {
            'Content-type': 'text/plain'
        });
        res.write('Request not permitted');
        res.end();
    };

    //FIXME: return a promise
    var sendMessages = function(filePath){
        var rapidProresponses = []
        Case = require('./case');

        Case.load(filePath).then(function (allCases) {
            var rapidProMessages = allCases.map(function (aCase) {
                return aCase.toRapidProMessage();
            });

            rapidProMessages.forEach(function (message) {
                message.send().then(function(responseBody) {
                    console.log(responseBody);
                });
            });
        });
        return rapidProresponses;
    };

    this.handle = function(req, res) {
        if (req.method == 'GET') {
            handleGet(req, res);
        } else if (req.method == 'POST') {
            handlePost(req, res);
        } else {
            handleProhibitted(req, res);
        }
    };
};
{'fraction_non_alphanumeric': 0.14338385907414994, 'fraction_numerical': 0.0024580090126997134, 'mean_word_length': 1.8406050029086678, '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': '2932123', 'n_tokens_mistral': 1380, 'n_tokens_neox': 1321, 'n_words': 256}