<commit_before>/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global require, exports */

(function () {
    "use strict";
    
    var address_manager = require("./address_manager.js");
    var config = require("./config.js");
    
    var jsonHeader = {"Content-Type": "application/json"};
    
    var objectToJson = function (obj) {
        
        if (obj === null || obj === undefined) {
            return "";
        }
        
        var out;
        
        if (config.PRETTY_PRINT_JSON_RESPONSE) {
            out = JSON.stringify(obj, null, config.JSON_PRETTY_PRINT_DELIMETER);
        } else {
            out = JSON.stringify(obj);
        }
        
        return out;
    };
    
    var generateError = function (msg) {
        var out = {"error": msg};
        return out;
    };
    
    var getCurrentAddress = function (response) {
        response.writeHead(200, jsonHeader);
        
        var item = address_manager.getCurrentAddress();
        
        var out = item;
        if (!item) {
            out = generateError("No current address.");
        }
        
        response.write(objectToJson(out));
        response.end();
    };
    
    var getAddresses = function (response) {
        response.writeHead(200, jsonHeader);
        
        var items = address_manager.getAddresses();
        
        response.write(objectToJson(items));
        response.end();
    };
    
    var handlers = {};
    handlers["/CURRENTADDRESS"] = getCurrentAddress;
    handlers["/GETADDRESSES"] = getAddresses;
    
    exports.handlers = handlers;
}());<commit_msg>first implimentation of api server infrastructure. two apis implimented. /addresses and /currentaddress.<commit_after>/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global require, exports */

(function () {
    "use strict";
    
    var address_manager = require("./address_manager.js");
    var config = require("./config.js");
    
    var jsonHeader = {"Content-Type": "application/json"};
    
    var objectToJson = function (obj) {
        
        if (obj === null || obj === undefined) {
            return "";
        }
        
        var out;
        
        if (config.PRETTY_PRINT_JSON_RESPONSE) {
            out = JSON.stringify(obj, null, config.JSON_PRETTY_PRINT_DELIMETER);
        } else {
            out = JSON.stringify(obj);
        }
        
        return out;
    };
    
    var generateError = function (msg) {
        var out = {"error": msg};
        return out;
    };
    
    var getCurrentAddress = function (response) {
        response.writeHead(200, jsonHeader);
        
        var item = address_manager.getCurrentAddress();
        
        var out = item;
        if (!item) {
            out = generateError("No current address.");
        }
        
        response.write(objectToJson(out));
        response.end();
    };
    
    var getAddresses = function (response) {
        response.writeHead(200, jsonHeader);
        
        var items = address_manager.getAddresses();
        
        response.write(objectToJson(items));
        response.end();
    };
    
    var handlers = {};
    handlers["/CURRENTADDRESS"] = getCurrentAddress;
    handlers["/ADDRESSES"] = getAddresses;
    
    exports.handlers = handlers;
}());
{'fraction_non_alphanumeric': 0.12529761904761905, 'fraction_numerical': 0.005357142857142857, 'mean_word_length': 1.9251523063533507, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, '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': '941452', 'n_tokens_mistral': 978, 'n_tokens_neox': 955, 'n_words': 213}