<commit_before>var send = require(CONFIG.root + "/core/send.js" ).send,
    getModule = require(CONFIG.root + "/core/model/orient.js").getModule,
    StaticServer = require("node-static" ).Server,
    modules = new StaticServer(CONFIG.root + "/modules");


// browser modules
exports.getModule = function(link) {

    if (!link.path || typeof link.path[2] == "undefined") {
        send.badrequest(link.res);
        return;
    }

    var module = link.path[2].replace(/[^0-9a-z_\-]/gi, "");

    if (module === "") {
        send.badrequest(link.res);
        return;
    }
    
    getModule(module, link.session.uid, function(err, res) {
        
        if (err || !res || !res.module) {
            send.notfound(link.res);
            return;
        }
            
        link.req.url = res.module + (res.dir || "") + "/" + link.path.slice(3).join("/").replace(/[^a-z0-9\/\.\-_]|\.\.\//gi, "");
        modules.serve(link.req, link.res);
    });
};
<commit_msg>comments and logging info in comp/modules.js module<commit_after>var send = require(CONFIG.root + "/core/send.js" ).send,
    getModule = require(CONFIG.root + "/core/model/orient.js").getModule,
    StaticServer = require("node-static" ).Server,
    modules = new StaticServer(CONFIG.root + "/modules");


// browser modules
exports.getModule = function(link) {

    // error checks
    if (!link.path || typeof link.path[2] == "undefined") {
        send.badrequest(link, "Module name missing");
        return;
    }

    // get the module name from the URL
    var module = link.path[2].replace(/[^0-9a-z_\-]/gi, "");

    // the module name must be almost alphanumeric
    if (module === "") {
        send.badrequest(link, "Incorrect module name in request URL");
        return;
    }

    // find the module in the database
    getModule(module, link.session.uid, function(err, res) {

        // error checks
        if (err || !res || !res.module) {
            send.notfound(link, err || ("Could not find module: " + module));
            return;
        }

        // now serve the module file
        link.req.url = res.module + (res.dir || "") + "/" + link.path.slice(3).join("/").replace(/[^a-z0-9\/\.\-_]|\.\.\//gi, "");
        modules.serve(link.req, link.res);
    });
};

{'fraction_non_alphanumeric': 0.18841220698805838, 'fraction_numerical': 0.006191950464396285, 'mean_word_length': 2.236051502145923, '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': '6503871', 'n_tokens_mistral': 731, 'n_tokens_neox': 716, 'n_words': 148}