<commit_before>'use strict';

var express = require('express');
var http = require('http');
var path = require('path');
var fs = require('fs');
var assert = require('assert');

module.exports = function(app, opts) {
  return new Http(app, opts);
};

var DEFAULT_HOST = '127.0.0.1';
var DEFAULT_PORT = 3001;

var createLogger = function(logger) {
  return express.logger({
    format: 'short',
    stream: {
      write: function(str) {
        if (!!logger) {
          logger.debug(str);
        } else {
          console.log(str);
        }
      }
    },
  })
};

var Http = function(app, opts) {
  opts = opts || {};
  this.app = app;
  this.http = express();
  // console.log('Http opts:', opts);
  this.host = opts.host || DEFAULT_HOST;
  this.port = opts.port || DEFAULT_PORT;

  if (!!opts.isCluster) {
    var serverId = app.getServerId();
    var params = serverId.split('-');
    var idx = parseInt(params[params.length - 1], 10);
    if(/\d+\+\+/.test(this.port)){

      this.port = parseInt(this.port.substr(0, this.port.length - 2));
    } else {
      assert.ok(false, 'http cluster expect http port format like "3000++"');
    }

    this.port = this.port + idx;
  }

  this.http.set('port', this.port);
  this.http.set('host', this.host);
  this.http.use(createLogger(opts.logger));
  this.http.use(express.bodyParser());
  this.http.use(express.urlencoded());
  this.http.use(express.json());
  this.http.use(express.methodOverride());
  this.http.use(this.http.router);<commit_msg>Revert "fixed test"<commit_after>'use strict';

var express = require('express');
var http = require('http');
var path = require('path');
var fs = require('fs');
var assert = require('assert');

module.exports = function(app, opts) {
  return new Http(app, opts);
};

var DEFAULT_HOST = '127.0.0.1';
var DEFAULT_PORT = 3001;

var createLogger = function(logger) {
  return express.logger({
    format: 'short',
    stream: {
      write: function(str) {
        if (!!logger) {
          logger.debug(str);
        } else {
          console.log(str);
        }
      }
    },
  })
};

var Http = function(app, opts) {
  opts = opts || {};
  this.app = app;
  this.http = express();
  // console.log('Http opts:', opts);
  this.host = opts.host || DEFAULT_HOST;
  this.port = opts.port || DEFAULT_PORT;

  if (!!opts.isCluster) {
    var serverId = app.getServerId();
    var params = serverId.split('-');
    var idx = parseInt(params[params.length - 1], 10);
    if(/\d+\+\+/.test(this.port)){

      this.port = parseInt(this.port.substr(0, this.port.length - 2));
    } else {
      assert.ok(false, 'http cluster expect http port format like "3000++"');
    }

    this.port = this.port + idx;
  }

  this.http.set('port', this.port);
  this.http.set('host', this.host);
  this.http.use(createLogger(opts.logger));
  this.http.use(express.urlencoded());
  this.http.use(express.json());
  this.http.use(express.methodOverride());
  this.http.use(this.http.router);
{'fraction_non_alphanumeric': 0.18579602827330866, 'fraction_numerical': 0.012790306294177045, 'mean_word_length': 3.043537414965986, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '4189673', 'n_tokens_mistral': 1034, 'n_tokens_neox': 1005, 'n_words': 210}