<commit_before>var express = require('express');
var router = express.Router();
var superAgent = require('superagent');
var environment = require('./environment.js');
var logger = require('./logger.js');

module.exports = (environment, logger) => {

	var _firstLetterToLowerCase = (world) => {
		return world.charAt(0).toLowerCase() + world.slice(1);
	};

	var _firstLetterToUpperCase = (world) => {
		return world.charAt(0).toUpperCase() + world.slice(1);
	};

	var _parseCookieString = (cookieString) => {
		var cookiePairs = cookieString.split('; ');

		var cookieName = null;
		var cookieValue = null;
		var cookieOptions = {
			path: '/',
			secure: false,
			expires: new Date('Fri, 31 Dec 9999 23:59:59 UTC'),
			httpOnly: false
		};

		cookiePairs.forEach((pair) => {
			var separatorIndexEqual =  pair.indexOf('=');
			var name = decodeURIComponent(_firstLetterToLowerCase(pair.substr(0, separatorIndexEqual)));
			var value = decodeURIComponent(pair.substr(separatorIndexEqual + 1));

			if (cookieOptions[name]) {
				var date = new Date(value);

				if (isNaN(date.getTime())) {
					cookieOptions[name] = value;
				} else {
					cookieOptions[name] = date;
				}

			} else {
				cookieName = name;
				cookieValue = value;
			}
		});

		return {
			name: cookieName,
			value: cookieValue,
			options: cookieOptions
		};
	};

	var _callRemoteServer = (req, res) => {
		var url = req.url;
		var httpRequest = null;

		if ((req.url.length > 1) && (req.url[req.url.length-1] === '/')) {
			url = url.substr(0, url.length - 1);
		}

		var proxyUrl = environment.$Proxy.server + url;

		logger.info(`API proxy: ${req.method} ${proxyUrl} query: ` + JSON.stringify(req.query));

		switch(req.method) {
			case 'POST':
				httpRequest = superAgent
					.post(proxyUrl)
					.send(req.body);
				break;
			case 'PUT':
				httpRequest = superAgent
					.put(proxyUrl)
					.send(req.body);
				break;
			case 'PATCH':
				httpRequest = superAgent
					.patch(proxyUrl)
					.send(req.body);
				break;
			case 'DELETE':
				httpRequest = superAgent
					.del(proxyUrl)
					.send(req.body);
				break;
			case 'GET':
				httpRequest = superAgent
					.get(proxyUrl)
					.query(req.query);
				break;
		}
<commit_msg>#! fix bug with duplication of GET parameters for proxy pass GET request<commit_after>var express = require('express');
var router = express.Router();
var superAgent = require('superagent');
var environment = require('./environment.js');
var logger = require('./logger.js');

module.exports = (environment, logger) => {

	var _firstLetterToLowerCase = (world) => {
		return world.charAt(0).toLowerCase() + world.slice(1);
	};

	var _firstLetterToUpperCase = (world) => {
		return world.charAt(0).toUpperCase() + world.slice(1);
	};

	var _parseCookieString = (cookieString) => {
		var cookiePairs = cookieString.split('; ');

		var cookieName = null;
		var cookieValue = null;
		var cookieOptions = {
			path: '/',
			secure: false,
			expires: new Date('Fri, 31 Dec 9999 23:59:59 UTC'),
			httpOnly: false
		};

		cookiePairs.forEach((pair) => {
			var separatorIndexEqual =  pair.indexOf('=');
			var name = decodeURIComponent(_firstLetterToLowerCase(pair.substr(0, separatorIndexEqual)));
			var value = decodeURIComponent(pair.substr(separatorIndexEqual + 1));

			if (cookieOptions[name]) {
				var date = new Date(value);

				if (isNaN(date.getTime())) {
					cookieOptions[name] = value;
				} else {
					cookieOptions[name] = date;
				}

			} else {
				cookieName = name;
				cookieValue = value;
			}
		});

		return {
			name: cookieName,
			value: cookieValue,
			options: cookieOptions
		};
	};

	var _callRemoteServer = (req, res) => {
		var url = req.url;
		var httpRequest = null;

		if ((req.url.length > 1) && (req.url[req.url.length-1] === '/')) {
			url = url.substr(0, url.length - 1);
		}

		var proxyUrl = environment.$Proxy.server + url;

		logger.info(`API proxy: ${req.method} ${proxyUrl} query: ` + JSON.stringify(req.query));

		switch(req.method) {
			case 'POST':
				httpRequest = superAgent
					.post(proxyUrl)
					.send(req.body);
				break;
			case 'PUT':
				httpRequest = superAgent
					.put(proxyUrl)
					.send(req.body);
				break;
			case 'PATCH':
				httpRequest = superAgent
					.patch(proxyUrl)
					.send(req.body);
				break;
			case 'DELETE':
				httpRequest = superAgent
					.del(proxyUrl)
					.send(req.body);
				break;
			case 'GET':
				httpRequest = superAgent
					.get(proxyUrl);
				break;
		}

{'fraction_non_alphanumeric': 0.15357142857142858, 'fraction_numerical': 0.009821428571428571, 'mean_word_length': 3.207511737089202, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '169927', 'n_tokens_mistral': 1832, 'n_tokens_neox': 1478, 'n_words': 327}