<commit_before>var http =require ("http") ;
var url =require ("url") ;
var path =require ("path") ;
var fs =require ("fs") ;
var requestLib =require ('request') ;
var gm =require ('googlemaps') ;
var util =require ('util') ;
//var elasticsearch =require ('elasticsearch') ;

// https://github.com/moshen/node-googlemaps
var GOOGLE_MAP_DISTANCE ="https://maps.googleapis.com/maps/api/distancematrix/output"
var MYKEY ="918108961534-r5dknljt9qk8fl9ovo1ntdp3qqipl719.apps.googleusercontent.com" ;
var MYSECRET ="<KEY>" ;

//var elasticSearch ='http://192.168.5.186:9200/poipointer/_search' ;

var port =process.argv [2] || 8888 ;
console.log ('Starting server @ http://localhost:' + port + '/') ;

// 50.7972419,4.3991661
// Entree+de+l'It+Tower/@50.8333589,4.3943596
// Hôtel+Solvay/@50.8333589,4.3943596
// Hôtel+Ciamberlani+asbl/@50.8333589,4.3943596
// Europe/@50.8333589,4.3943596
// Tour+D'Angle/@50.8333589,4.3943596

// http://localhost:8888/destination?origin=50.7972419,4.3991661&destination=50.8333589,4.3943596

function PostCode (categories, bodyReq, response) {
    // Build the post string from an object
    var post_data =JSON.stringify (bodyReq) ;

    // An object of options to indicate where to post to
    var post_options ={
        host: '127.0.0.1',
        port: '9200',
        path: '/poipointer' + categories + '/_search',
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
            'Content-Length': post_data.length
        }
    } ;

    // Set up the request
    var post_req =http.request (post_options, function (res) {
    res.setEncoding('utf8');
        res.on ('data', function (chunk) {
            console.log ('Response: ' + chunk) ;
            //var jsc =JSON.parse (chunk) ;
            //console.log (jsc.hits) ;
            //response.write (JSON.stringify (jsc)) ;
            response.write (chunk) ;
            response.end () ;
        }) ;
    }) ;

    // post the data
    post_req.write (post_data) ;
    post_req.end () ;
}

http.createServer (function (request, response) {

	var uri =url.parse (request.url).pathname ;
    console.log (uri) ;
    
	if ( uri == '/distance' ) {
        var params =url.parse (request.url, true).query ;
        
        //gm.reverseGeocode (gm.checkAndConvertPoint ([41.850033, -87.6500523]), function (err, data) {
        //  util.puts (JSON.stringify (data)) ;
        //}) ;
        //gm.distance ('48.3421719,-4.7131939', '48.3397471,-4.7157371', function (err, data) {
        var units =params.units || 'metric' ; // 'imperial ' ;
        gm.distance (params.origin, params.destination, function (err, data) {
                console.log (data) ;
                //util.puts (JSON.stringify (data)) ;
                response.write (JSON.stringify (data)) ;
				response.end () ;
                //for ( var attributename in data ) {
                //    console.log (attributename + ": " + data [attributename]) ;
                //}
            },
            null, //MYKEY,
            'walking',
            null,<commit_msg>reponse was truncated<commit_after>var http =require ("http") ;
var url =require ("url") ;
var path =require ("path") ;
var fs =require ("fs") ;
var requestLib =require ('request') ;
var gm =require ('googlemaps') ;
var util =require ('util') ;
//var elasticsearch =require ('elasticsearch') ;

// https://github.com/moshen/node-googlemaps
var GOOGLE_MAP_DISTANCE ="https://maps.googleapis.com/maps/api/distancematrix/output"
var MYKEY ="918108961534-r5dknljt9qk8fl9ovo1ntdp3qqipl719.apps.googleusercontent.com" ;
var MYSECRET ="<KEY>" ;

//var elasticSearch ='http://192.168.5.186:9200/poipointer/_search' ;

var port =process.argv [2] || 8888 ;
console.log ('Starting server @ http://localhost:' + port + '/') ;

// 50.7972419,4.3991661
// Entree+de+l'It+Tower/@50.8333589,4.3943596
// Hôtel+Solvay/@50.8333589,4.3943596
// Hôtel+Ciamberlani+asbl/@50.8333589,4.3943596
// Europe/@50.8333589,4.3943596
// Tour+D'Angle/@50.8333589,4.3943596

// http://localhost:8888/destination?origin=50.7972419,4.3991661&destination=50.8333589,4.3943596

function PostCode (categories, bodyReq, response) {
    // Build the post string from an object
    var post_data =JSON.stringify (bodyReq) ;

    // An object of options to indicate where to post to
    var post_options ={
        host: '192.168.5.186', //'127.0.0.1',
        port: '9200',
        path: '/poipointer' + categories + '/_search',
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
            'Content-Length': post_data.length
        }
    } ;

    // Set up the request
    var jsonResponse ='' ;
    var post_req =http.request (post_options, function (res) {
        res.setEncoding('utf8');
        res.on ('data', function (chunk) {
            //console.log ('Response: ' + chunk) ;
            jsonResponse +=chunk ;
        }) ;
        res.on ('end', function () {
            var jsc ;
            try {
                jsc =JSON.parse (jsonResponse) ;
                //console.log (jsc) ;
            } catch ( e ) {
                // An error has occured, handle it, by e.g. logging it
                console.log (e) ;
            }
            //response.write (JSON.stringify (jsc)) ;

            response.writeHead (200, { 'Content-Type': 'application/json', "Access-Control-Allow-Origin": '*' }) ;
            response.write (jsonResponse) ; // , null, 3
            response.end () ;
        }) ;
    }) ;

    // post the data
    post_req.write (post_data) ;
    post_req.end () ;
}

http.createServer (function (request, response) {

	var uri =url.parse (request.url).pathname ;
    console.log (uri) ;
    
	if ( uri == '/distance' ) {
        var params =url.parse (request.url, true).query ;
        
        //gm.reverseGeocode (gm.checkAndConvertPoint ([41.850033, -87.6500523]), function (err, data) {
        //  util.puts (JSON.stringify (data)) ;
        //}) ;
        //gm.distance ('48.3421719,-4.7131939', '48.3397471,-4.7157371', function (err, data) {
        var units =params.units || 'metric' ; // 'imperial ' ;
        gm.distance (params.origin, params.destination, function (err, data) {
                //console.log (data) ;
                response.writeHead (200, { 'Content-Type': 'application/json', "Access-Control-Allow-Origin": '*' }) ;
                response.write (JSON.stringify (data)) ;
				response.end () ;
                //for ( var attributename in data ) {
                //    console.log (attributename + ": " + data [attributename]) ;
                //}
            },
            null, //MYKEY,
            'walking',
            null,
{'fraction_non_alphanumeric': 0.16112684453718884, 'fraction_numerical': 0.0746758086152929, 'mean_word_length': 2.269980506822612, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 5, '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': '4775139', 'n_tokens_mistral': 2521, 'n_tokens_neox': 2189, 'n_words': 450}