<commit_before>'use strict';

const fs = require('fs-promise');
const request = require('request-promise');
const os = require('os');

const app = process.env.APP;
const hosts = os.platform() === 'win32'
        ? `${process.env.SystemRoot}/System32/drivers/etc/hosts`
        : '/etc/hosts';
const logger = console;
const port = process.env.PORT || 4001;

const update = () => {
    logger.info('Updating ip address');

    fs.readFile(hosts)
        .then((file) => file.toString()
                .split(/\r\n|\n/)
                .map((line) =>
                    line.replace(/\s\s+/, ' ')
                        .replace(/(#.*$)/, '')
                        .match(/^\s*([^\s]+)\s+(([^\s]+\s*)+)$/)
                )
                .filter((m) => m)
                .map((m) => [m[1], m[2].split(/\s+/)])
                .map((m) => m[1].indexOf(app) >= 0 && m[0])
                .find((a) => a)
        )
        .then(
            (address) => 
                address || Promise.reject(new Error('Failed to resolve app to address'))
        )
        .then((address) => request({
                method: 'PUT',
                uri: `http://etcd:${port}/v2/keys/${app}?value=${address}`,
                json: true,
            })
            .then((data) => {
                logger.info(
                    'Addres of',
                    data.node.key,
                    'has been updated to',
                    data.node.value,
                    'from',
                    data.prevNode && data.prevNode.value || null
                );
            })
        )
        .catch((e) => logger.error(e))
        ;
};<commit_msg>Support port number<commit_after>'use strict';

const fs = require('fs-promise');
const request = require('request-promise');
const os = require('os');

const app = process.env.APP;
const hosts = os.platform() === 'win32'
        ? `${process.env.SystemRoot}/System32/drivers/etc/hosts`
        : '/etc/hosts';
const logger = console;
const etcdPort = process.env.ETCD_PORT || 4001;
const port = process.env.PORT;

const update = () => {
    logger.info('Updating ip address');

    fs.readFile(hosts)
        .then((file) => file.toString()
                .split(/\r\n|\n/)
                .map((line) =>
                    line.replace(/\s\s+/, ' ')
                        .replace(/(#.*$)/, '')
                        .match(/^\s*([^\s]+)\s+(([^\s]+\s*)+)$/)
                )
                .filter((m) => m)
                .map((m) => [m[1], m[2].split(/\s+/)])
                .map((m) => m[1].indexOf(app) >= 0 && m[0])
                .find((a) => a)
        )
        .then(
            (address) => 
                address || Promise.reject(new Error('Failed to resolve app to address'))
        )
        .then((address) => port ? `${address}:${port}` : address)
        .then((address) => request({
                method: 'PUT',
                uri: `http://etcd:${port}/v2/keys/${app}?value=${address}`,
                json: true,
            })
            .then((data) => {
                logger.info(
                    'Addres of',
                    data.node.key,
                    'has been updated to',
                    data.node.value,
                    'from',
                    data.prevNode && data.prevNode.value || null
                );
            })
        )
        .catch((e) => logger.error(e))
        ;
};
{'fraction_non_alphanumeric': 0.19214997070884593, 'fraction_numerical': 0.008201523140011716, 'mean_word_length': 1.2842809364548495, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 28, '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': '1604612', 'n_tokens_mistral': 1059, 'n_tokens_neox': 994, 'n_words': 179}