<commit_before>var HttpDispatcher   = require('httpdispatcher');
var fs               = require('fs');
var path             = require('path');
var http             = require('http');
var https            = require('https');
var recursive        = require('recursive-readdir');
var simpleNodeLogger = require('simple-node-logger');

https.globalAgent.options.secureProtocol = 'SSLv3_method';

var removeWWW = function(url) {
	if(url.indexOf('www') > -1)
		return url.substring(4, url.length);

	return url;
};

var removePort = function(host) {
	indexOfPort = host.indexOf(':');

	if(indexOfPort > -1) 
		return host.substring(0, indexOfPort);

	return host;
};

var getFileType = function(file) {
	var suffix = '';
	for (var i = file.length - 1; i >= 0 && file[i] != '.'; i--) {
		suffix += file[i];
	}

	return suffix.split('').reverse().join('');
};

var getFilesFromDirectory = function(directory, filesToIgnore, directoriesToIgnore, callback) {
	var ignoreFunc = function(file, stats) {
		if(stats.isDirectory() && directoriesToIgnore.indexOf(path.basename(file)) > -1)
			return true;
		else if(stats.isFile() && filesToIgnore.indexOf(path.basename(file)) > -1)
			return true;
		else return false;
	};
	 
	recursive(directory, ['.htaccess', ignoreFunc], function (err, files) {
	  callback(files);
	});
};

var constructURLFromPath = function(dom, filepath) {
	var index = filepath.indexOf(dom.baseDirectory);
	if(index > -1) {
		return filepath.substring(index + dom.baseDirectory.length, filepath.length);
	}

	return '';
};

StarkServer = function() {
	var self            = this;
	this.domains        = [];
	this.cgis           = [];
	this.HTTPPort       = 8080;
	this.HTTPSPort      = 8081;
	this.domainIndexSet = {};
	this.mimeTypeLookup = require('mime-types').lookup;
	this.logger         = simpleNodeLogger.createSimpleLogger({
		logFilePath:'StarkServer.log',
		timestampFormat:'YY-MM-DD HH:MM:ss'
	});

	this.handleRequest = function(req, res) {
		try {
			var requestedHost = req.headers.host;
			requestedHost     = removeWWW(requestedHost);
			requestedHost     = removePort(requestedHost);
			
			for(var i in self.domains) {
				if(requestedHost == self.domains[i].host)
					self.domains[i].dispatcher.dispatch(req, res);
			}
	    }
	    catch(err) {
	    	self.logger.error('Problem handling request: ', err);
	    }
	};

	this.HTTPServer = http.createServer(this.handleRequest);
};

StarkServer.prototype.checkIfFileExists = function(file) {
	try {
		return fs.statSync(file).isFile();
	}
	catch(err) {
		if(err.code === 'ENOENT')
			return false;
		else throw e;
	}
};<commit_msg>Changed name of variable so it is no longer undefined.<commit_after>var HttpDispatcher   = require('httpdispatcher');
var fs               = require('fs');
var path             = require('path');
var http             = require('http');
var https            = require('https');
var recursive        = require('recursive-readdir');
var simpleNodeLogger = require('simple-node-logger');

https.globalAgent.options.secureProtocol = 'SSLv3_method';

var removeWWW = function(url) {
	if(url.indexOf('www') > -1)
		return url.substring(4, url.length);

	return url;
};

var removePort = function(host) {
	indexOfPort = host.indexOf(':');

	if(indexOfPort > -1) 
		return host.substring(0, indexOfPort);

	return host;
};

var getFileType = function(file) {
	var suffix = '';
	for (var i = file.length - 1; i >= 0 && file[i] != '.'; i--) {
		suffix += file[i];
	}

	return suffix.split('').reverse().join('');
};

var getFilesFromDirectory = function(directory, filesToIgnore, directoriesToIgnore, callback) {
	var ignoreFunc = function(file, stats) {
		if(stats.isDirectory() && directoriesToIgnore.indexOf(path.basename(file)) > -1)
			return true;
		else if(stats.isFile() && filesToIgnore.indexOf(path.basename(file)) > -1)
			return true;
		else return false;
	};
	 
	recursive(directory, ['.htaccess', ignoreFunc], function (err, files) {
	  callback(files);
	});
};

var constructURLFromPath = function(dom, filepath) {
	var index = filepath.indexOf(dom.baseDirectory);
	if(index > -1) {
		return filepath.substring(index + dom.baseDirectory.length, filepath.length);
	}

	return '';
};

StarkServer = function() {
	var self            = this;
	this.domains        = [];
	this.cgis           = [];
	this.HTTPPort       = 8080;
	this.HTTPSPort      = 8081;
	this.domainIndexSet = {};
	this.mimeTypeLookup = require('mime-types').lookup;
	this.logger         = simpleNodeLogger.createSimpleLogger({
		logFilePath:'StarkServer.log',
		timestampFormat:'YY-MM-DD HH:MM:ss'
	});

	this.handleRequest = function(req, res) {
		try {
			var requestedHost = req.headers.host;
			requestedHost     = removeWWW(requestedHost);
			requestedHost     = removePort(requestedHost);
			
			for(var i in self.domains) {
				if(requestedHost == self.domains[i].host)
					self.domains[i].dispatcher.dispatch(req, res);
			}
	    }
	    catch(err) {
	    	self.logger.error('Problem handling request: ', err);
	    }
	};

	this.HTTPServer = http.createServer(this.handleRequest);
};

StarkServer.prototype.checkIfFileExists = function(file) {
	try {
		return fs.statSync(file).isFile();
	}
	catch(err) {
		if(err.code === 'ENOENT')
			return false;
		else throw err;
	}
};
{'fraction_non_alphanumeric': 0.15389005136009132, 'fraction_numerical': 0.0068480121742438655, 'mean_word_length': 3.5210662080825452, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5765804', 'n_tokens_mistral': 1854, 'n_tokens_neox': 1707, 'n_words': 341}