<commit_before>
import nprogress from 'nprogress';
import appconfig from '../config';

//	Actions
import ConfigActions from '../actions/ConfigActions';

class CentralConfigAPIUtils {

    constructor()
    {
        this.baseUrl = "";
		
		//	Do a 'truthy' check to see if the config item is set
		//	Confused?  See https://stackoverflow.com/a/5515349/19020
		if(appconfig.serviceBaseHostPort)
		{
			this.baseUrl = `//${appconfig.serviceBaseHostPort}`;
		}
    }

    //	Gets all configuration items from the server
    getAllConfigItems() {        

        console.time("Fetched config data");

        //  Format the url
        let url = `${this.baseUrl}/config/getall`;
        
        nprogress.start();

        return fetch(url,
        {
            method: 'get',
            mode: 'cors'
        })
        .then(
            function (response) {
                nprogress.done();
                console.timeEnd("Fetched config data");
                
                if (response.status !== 200) {
                    console.log('Looks like there was a problem. Status Code: ' + response.status);
                    return;
                }

                // Receive system state
                response.json().then(function (body) {
                    //  Call the action to receive the data:
                    ConfigActions.recieveConfigData(body.data);                    
                });
            }
        )
        .catch(function (err) {
            console.log('Fetch Error :-S', err);
        });
    }

    //  Removes a configuration item
    removeConfigItem(configItem) {

        //  Format the url
        let url = `${this.baseUrl}/config/remove`;

        console.log("Removing config: %O", configItem)
        console.time("Called remove");

        return fetch(url,
        {
            mode: 'cors',
            method: 'post',
            body: JSON.stringify(configItem)
        })
        .then(
            function (response) {
                console.timeEnd("Called remove");

                if (response.status !== 200) {
                    console.log('Looks like there was a problem. Status Code: ' + response.status);
                    return;
                }

                // Receive system state
                response.json().then(function (body) {
                    ConfigActions.recieveRemovedConfigData(configItem);                    
                });
            }
        )
        .catch(function (err) {
            console.log('Fetch Error :-S', err);
        });
    }

    //  Creates/updates a configuration item
    setConfigItem(configItem) {

        //  Format the url
        let url = `${this.baseUrl}/config/set`;

        console.log("Setting config: %O", configItem)
        console.time("Set config data");

        return fetch(url,
        {
            mode: 'cors',
            method: 'post',
            body: JSON.stringify(configItem)
        })
        .then(
            function (response) {
                console.timeEnd("Set config data");
<commit_msg>Update to use content-type header on requests<commit_after>
import nprogress from 'nprogress';
import appconfig from '../config';

//	Actions
import ConfigActions from '../actions/ConfigActions';

class CentralConfigAPIUtils {

    constructor()
    {
        this.baseUrl = "";
		
		//	Do a 'truthy' check to see if the config item is set
		//	Confused?  See https://stackoverflow.com/a/5515349/19020
		if(appconfig.serviceBaseHostPort)
		{
			this.baseUrl = `//${appconfig.serviceBaseHostPort}`;
		}
    }

    //	Gets all configuration items from the server
    getAllConfigItems() {        

        console.time("Fetched config data");

        //  Format the url
        let url = `${this.baseUrl}/config/getall`;
        
        nprogress.start();

        return fetch(url,
        {
            method: 'get',
            mode: 'cors',
            headers:{'content-type': 'application/json'}
        })
        .then(
            function (response) {
                nprogress.done();
                console.timeEnd("Fetched config data");
                
                if (response.status !== 200) {
                    console.log('Looks like there was a problem. Status Code: ' + response.status);
                    return;
                }

                // Receive system state
                response.json().then(function (body) {
                    //  Call the action to receive the data:
                    ConfigActions.recieveConfigData(body.data);                    
                });
            }
        )
        .catch(function (err) {
            console.log('Fetch Error :-S', err);
        });
    }

    //  Removes a configuration item
    removeConfigItem(configItem) {

        //  Format the url
        let url = `${this.baseUrl}/config/remove`;

        console.log("Removing config: %O", configItem)
        console.time("Called remove");

        return fetch(url,
        {
            mode: 'cors',
            method: 'post',
            body: JSON.stringify(configItem),
            headers:{'content-type': 'application/json'}
        })
        .then(
            function (response) {
                console.timeEnd("Called remove");

                if (response.status !== 200) {
                    console.log('Looks like there was a problem. Status Code: ' + response.status);
                    return;
                }

                // Receive system state
                response.json().then(function (body) {
                    ConfigActions.recieveRemovedConfigData(configItem);                    
                });
            }
        )
        .catch(function (err) {
            console.log('Fetch Error :-S', err);
        });
    }

    //  Creates/updates a configuration item
    setConfigItem(configItem) {

        //  Format the url
        let url = `${this.baseUrl}/config/set`;

        console.log("Setting config: %O", configItem)
        console.time("Set config data");

        return fetch(url,
        {
            mode: 'cors',
            method: 'post',
            body: JSON.stringify(configItem),
            headers:{'content-type': 'application/json'}
        })
        .then(
            function (response) {
                console.timeEnd("Set config data");

{'fraction_non_alphanumeric': 0.11555415617128463, 'fraction_numerical': 0.005667506297229219, 'mean_word_length': 1.4192688499619193, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '5144938', 'n_tokens_mistral': 1733, 'n_tokens_neox': 1614, 'n_words': 384}