<commit_before>var express = require('express');

var OAE = require('./OAE');

var tenants = [];

///////////
// Model //
///////////

module.exports.Tenant = function(id, name, port) {
    
    var that = {};

    that.id = id;
    that.name = name;
    that.port = isNaN(port) ? parseInt(port) : port;

    module.exports.startTenant(that);
    tenants.push(that);
    return that;
    
};

///////////////
// Functions //
///////////////

module.exports.getTenants = function() {
    return tenants;
};

module.exports.startTenant = function(tenant) {
    if (tenant && tenant.port) {
        tenant.server = express();
        tenant.server.listen(tenant.port);
        registerAPI(tenant);
        console.log('Start tenant "' + tenant.name + '" on port ' + tenant.port);
    }
};

module.exports.stopTenant = function(tenant) {
    if (tenant && tenant.server) {
        tenant.server.close();
    }
};

/////////
// API //
/////////

var registerAPI = function(tenant) {
    
    tenant.server.get('/tenant/whoami', function(req, res) {
        res.send(tenant.name);
    });
    
    var modules = OAE.getAvailableModules(function(modules) {
        for (var m = 0; m < modules.length; m++) {
            console.log(modules[m]);
            require(modules[m] + "/lib/rest")(tenant);
        }
    });
    
};<commit_msg>Fixing issue with modules without rest.js file<commit_after>var express = require('express');

var OAE = require('./OAE');
var IO = require('./IO');

var tenants = [];

///////////
// Model //
///////////

module.exports.Tenant = function(id, name, port) {
    
    var that = {};

    that.id = id;
    that.name = name;
    that.port = isNaN(port) ? parseInt(port) : port;

    module.exports.startTenant(that);
    tenants.push(that);
    return that;
    
};

///////////////
// Functions //
///////////////

module.exports.getTenants = function() {
    return tenants;
};

module.exports.startTenant = function(tenant) {
    if (tenant && tenant.port) {
        tenant.server = express();
        tenant.server.listen(tenant.port);
        registerAPI(tenant);
        console.log('Start tenant "' + tenant.name + '" on port ' + tenant.port);
    }
};

module.exports.stopTenant = function(tenant) {
    if (tenant && tenant.server) {
        tenant.server.close();
    }
};

/////////
// API //
/////////

var registerAPI = function(tenant) {
    
    tenant.server.get('/tenant/whoami', function(req, res) {
        res.send(tenant.name);
    });
    
    var modules = OAE.getAvailableModules(function(modules) {
        for (var m = 0; m < modules.length; m++) {
            var path = "node_modules/" + module + "/lib/rest.js";
            IO.pathExists(path, function(exists) {
                if (exists) {
                    require(modules[m] + "/lib/rest")(tenant);
                }
            });
        }
    });
    
};
{'fraction_non_alphanumeric': 0.20411006617903169, 'fraction_numerical': 0.0006966213862765587, 'mean_word_length': 1.9216683621566633, 'pattern_counts': {'":': 0, '<': 5, '<?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': '652345', 'n_tokens_mistral': 894, 'n_tokens_neox': 910, 'n_words': 165}