<commit_before>"use strict";

let resources = require("./resources")
  , path = require("path")
  , fs = require("fs")
  , chalk = require("chalk");

module.exports = function (root, app, domain, multiple_domains) {
  let files = 
    resources.getFiles(process.env.CONFIG_PATH + "/middleware")
    .concat(resources.getFiles(process.env.CONFIG_PATH + "/middleware/" + domain));

  console.log(chalk.green(multiple_domains ? "\t\t\t" : "\t\t", "Middleware:"));

  if (files.length == 0) console.log(chalk.yellow(multiple_domains ? "\t\t\t\t" : "\t\t\t", "none"));

  for (let i in files) {
    let middleware = files[i]
      , name = path.basename(path.basename(middleware, '.json'), '.js');

    if (!fs.existsSync(process.cwd() + "/node_modules/" + name)) {
      console.log(chalk.red(multiple_domains ? "\t\t\t\t" : "\t\t\t", name, "is missing please run 'npm install ", name, " --save'"));
      continue;
    }

    console.log(chalk.green(multiple_domains ? "\t\t\t\t" : "\t\t\t", name));
    
    let mod = require(process.cwd() + "/node_modules/" + name)
      , options = require(middleware);

    if (options.constructor === Function) {
      options(root, app, mod);
    } else {
      app.use(mod(options));
    }
  }
}<commit_msg>Fixed issue where socket middleware was not applied<commit_after>"use strict";

let resources = require("./resources")
  , path = require("path")
  , fs = require("fs")
  , chalk = require("chalk");

module.exports = function (root, app, domain, multiple_domains) {
  http(root, app, domain, multiple_domains);
  socket(root, app, domain, multiple_domains);
}

let http = function (root, app, domain, multiple_domains) {
  let files = 
    resources.getFiles(process.env.CONFIG_PATH + "/middleware")
    .concat(resources.getFiles(process.env.CONFIG_PATH + "/middleware/" + domain));

  console.log(chalk.green(multiple_domains ? "\t\t\t" : "\t\t", "Middleware:"));

  if (files.length == 0) console.log(chalk.yellow(multiple_domains ? "\t\t\t\t" : "\t\t\t", "none"));

  for (let i in files) {
    let middleware = files[i]
      , name = path.basename(path.basename(middleware, ".json"), ".js");

    if (name === "index") {
      app.use(require(middleware));
      continue;
    } else if (!fs.existsSync(process.cwd() + "/node_modules/" + name)) {
      console.log(chalk.red(multiple_domains ? "\t\t\t\t" : "\t\t\t", name, "is missing please run 'npm install ", name, " --save'"));
      continue;
    }

    console.log(chalk.green(multiple_domains ? "\t\t\t\t" : "\t\t\t", name));
    
    let mod = require(process.cwd() + "/node_modules/" + name)
      , options = require(middleware);

    if (options.constructor === Function) {
      options(root, app, mod);
    } else {
      app.use(mod(options));
    }
  }
}

let socket = function (root, app, domain, multiple_domains) {
  let files = 
    resources.getFiles(process.env.CONFIG_PATH + "/middleware/socket")
    .concat(resources.getFiles(process.env.CONFIG_PATH + "/middleware/" + domain + "/socket"));

  if (files.length == 0) console.log(chalk.yellow(multiple_domains ? "\t\t\t\t" : "\t\t\t", "none"));

  for (let i in files) {
    let middleware = files[i]
      , name = path.basename(path.basename(middleware, ".json"), ".js");

    if (name === "index") {
      require(middleware)(root, app);
      continue;
    } else if (!fs.existsSync(process.cwd() + "/node_modules/" + name)) {
      console.log(chalk.red(multiple_domains ? "\t\t\t\t" : "\t\t\t", name, "is missing please run 'npm install ", name, " --save'"));
      continue;
    }

    console.log(chalk.green(multiple_domains ? "\t\t\t\t" : "\t\t\t", name));
    
    let mod = require(process.cwd() + "/node_modules/" + name)
      , options = require(middleware);

    if (options.constructor === Function) {
      options(root, app, mod);
    } else {
      app.io.use(mod(options));
    }
  }
}
{'fraction_non_alphanumeric': 0.19329896907216496, 'fraction_numerical': 0.0007731958762886598, 'mean_word_length': 3.1686358754027926, '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': '6093016', 'n_tokens_mistral': 1368, 'n_tokens_neox': 1320, 'n_words': 271}