<commit_before>// require Johnny's static
var JohnnysStatic = require("johnnys-node-static"),
    http = require('http'),
    qs   = require('querystring');

// set static server: public folder
JohnnysStatic.setStaticServer({root: "./public"});
var Contributions = require("./contributions");

// set routes
JohnnysStatic.setRoutes({
    "/":       { "url": "/html/index.html" }
});

// create http server
http.createServer(function(req, res) {

    // safe serve
    if (JohnnysStatic.exists(req, res)) {
        // serve file
        JohnnysStatic.serve(req, res, function (err) {
            // not found error
            if (err.code === "ENOENT") {
                res.end("404 - Not found.");
                return;
            }

            // other error
            res.end(JSON.stringify(err));
        });
        return;
    }

    if (req.url === "/get-zip") {
        getFormData(req, res, function (err, data) {

            if (err) { return sendResponse(req, res, err, 400); }
<commit_msg>Handle request data.<commit_after>// require Johnny's static
var JohnnysStatic = require("johnnys-node-static"),
    http = require('http'),
    qs   = require('querystring');

// set static server: public folder
JohnnysStatic.setStaticServer({root: "./public"});
var Contributions = require("./contributions");

// set routes
JohnnysStatic.setRoutes({
    "/":       { "url": "/html/index.html" }
});

// create http server
http.createServer(function(req, res) {

    // safe serve
    if (JohnnysStatic.exists(req, res)) {
        // serve file
        JohnnysStatic.serve(req, res, function (err) {
            // not found error
            if (err.code === "ENOENT") {
                res.end("404 - Not found.");
                return;
            }

            // other error
            res.end(JSON.stringify(err));
        });
        return;
    }

    if (req.url === "/get-zip") {
        getFormData(req, res, function (err, formData) {

            if (err) { return sendResponse(req, res, err, 400); }
            console.log(typeof formData);
            if (typeof formData === "string") {
                try {
                    formData = JSON.parse(formData);
                } catch (e) {
                    return sendResponse(req, res, e, 400);
                }
            }
            if (formData.constructor !== Object) {
                return sendResponse(req, res, "Invalid request data.", 400);
            }

            console.dir(formData);

{'fraction_non_alphanumeric': 0.14841556357801844, 'fraction_numerical': 0.007220216606498195, 'mean_word_length': 1.8405466970387243, 'pattern_counts': {'":': 4, '<': 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': '3562259', 'n_tokens_mistral': 750, 'n_tokens_neox': 700, 'n_words': 171}