<commit_before>var http = require("http");
var url = require("url");
var qs = require('query-string');
var mongoose = require('mongoose');

const PORT = process.env.PORT || 5000;
const MONGODBURI = process.env.MONGOLAB_URI;
const DEFAULTURL = process.env.DEFAULT_REDIRECT_URL || "www.jewelry.com";
const PROTOCOL = process.env.LANDING_PROTOCOL || "http";

mongoose.connect(MONGODBURI);
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'db connection error:'));

var linkSchema = new mongoose.Schema({
	requestURL: String,
	dest: {
		hostname: String,
		pathname: String,
		search: String,
		hash: String
	}
});
var Link = mongoose.model('Link', linkSchema);

function mergeParams(userParams, dbParams) {
	var u = qs.parse(userParams);
	var d = qs.parse(dbParams);
	for (var val in u) {
		d[val] = d[val] || u[val];
	}
	return qs.stringify(d);
}

function handleURL(hostname, pathname, search) {
	var out = Link.findOne({ requestURL: hostname + pathname })
		.select('dest').lean()
		.exec(function(err, result) {
			if (err) throw err;
			result = result || { hostname: DEFAULTURL };
			result.search = mergeParams(search, result.search || "");
			result.protocol = PROTOCOL;
			console.log("URL DEBUG:\n"+result.hostname+"\n"+result);
			return result;
		});
		return url.format(out);
}

var server = http.createServer(function(req, res) {
	var url_parts = url.parse(req.url);
	var out = handleURL(url_parts.hostname, url_parts.pathname, url_parts.search);
	res.writeHead(301, {
		"Location": out
	});
	res.end();
}).listen(PORT);<commit_msg>more debug<commit_after>var http = require("http");
var url = require("url");
var qs = require('query-string');
var mongoose = require('mongoose');

const PORT = process.env.PORT || 5000;
const MONGODBURI = process.env.MONGOLAB_URI;
const DEFAULTURL = process.env.DEFAULT_REDIRECT_URL || "www.jewelry.com";
const PROTOCOL = process.env.LANDING_PROTOCOL || "http";

mongoose.connect(MONGODBURI);
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'db connection error:'));

var linkSchema = new mongoose.Schema({
	requestURL: String,
	dest: {
		hostname: String,
		pathname: String,
		search: String,
		hash: String
	}
});
var Link = mongoose.model('Link', linkSchema);

function mergeParams(userParams, dbParams) {
	var u = qs.parse(userParams);
	var d = qs.parse(dbParams);
	for (var val in u) {
		d[val] = d[val] || u[val];
	}
	return qs.stringify(d);
}

function handleURL(hostname, pathname, search) {
	var out = Link.findOne({ requestURL: hostname + pathname })
		.select('dest').lean()
		.exec(function(err, result) {
			if (err) throw err;
			result = result || { hostname: DEFAULTURL };
			result.search = mergeParams(search, result.search || "");
			result.protocol = PROTOCOL;
			console.log("URL DEBUG:\n"+result.hostname+"\n"+result);
			return result;
		});
		return url.format(out);
}

var server = http.createServer(function(req, res) {
	var url_parts = url.parse(req.url);
	var out = handleURL(url_parts.hostname, url_parts.pathname, url_parts.search);
	// res.writeHead(301, {
// 		"Location": out
// 	});
	res.end("hello");
}).listen(PORT);
{'fraction_non_alphanumeric': 0.1646012074992056, 'fraction_numerical': 0.0044486812837623135, 'mean_word_length': 4.755027422303473, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '3118616', 'n_tokens_mistral': 1151, 'n_tokens_neox': 1124, 'n_words': 246}