<commit_before>/**
 * @copyright Copyright (c) 2019 <NAME> <<EMAIL>>
 */
'use strict';

const Base = require('./Module');

module.exports = class Application extends Base {

    static getConstants () {
        return {
            DEFAULT_COMPONENTS: {
                'bodyParser': {},
                'formatter': {},
                'router': {},
                'urlManager': {},
                'view': {}
            },
            EVENT_AFTER_START: 'afterStart'
        };
    }

    constructor (config) {
        super(config);
        this.configName = this.configName || process.env.NODE_ENV;
        this.mainEngine = this.createEngine();
    }

    getBaseName () {
        if (!this.hasOwnProperty('_baseName')) {
            this._baseName = StringHelper.camelToId(StringHelper.trimEnd(this.constructor.name, 'Application'));
        }
        return this._baseName;
    }

    async init () {
        await super.init();
        this.baseUrl = this.mountPath === '/' ? this.mountPath : `${this.mountPath}/`;
    }

    getRoute (url) {
        if (this._route === undefined) {
            this._route = this.mountPath === '/' ? '' : this.mountPath;
        }
        return url ? `${this._route}/${url}` : this._route;
    }

    createFullName () {
        return this.getBaseName();
    }

    createRelativeName () {
        return '';
    }

    start () {
        this.attachHandlers();
        return this.createServer();
    }

    afterStart () {
        return this.trigger(this.EVENT_AFTER_START);
    }

    attachHandlers () {
        super.attachHandlers();
        this.mainEngine.attachChild(this.mountPath, this.engine);
    }

    createServer () {
        return new Promise((resolve, reject) => {
            this.server = this.mainEngine.createServer().on('error', err => {
                this.log('error', 'Server error', err);
                reject(err);
            }).listen(this.getConfig('port'), ()=> {
                this.log('info', `Started ${this.fullName} as`, this.server.address());
                this.log('info', `Mounted ${this.fullName} as ${this.mountPath}`);
                this.afterStart().then(resolve);
            });
        });
    }<commit_msg>Add server port to spawn configuration<commit_after>/**
 * @copyright Copyright (c) 2019 <NAME> <<EMAIL>>
 */
'use strict';

const Base = require('./Module');

module.exports = class Application extends Base {

    static getConstants () {
        return {
            DEFAULT_COMPONENTS: {
                'bodyParser': {},
                'formatter': {},
                'router': {},
                'urlManager': {},
                'view': {}
            },
            EVENT_AFTER_START: 'afterStart'
        };
    }

    constructor (config) {
        super(config);
        this.configName = this.configName || process.env.NODE_ENV;
        this.mainEngine = this.createEngine();
    }

    getBaseName () {
        if (!this.hasOwnProperty('_baseName')) {
            this._baseName = StringHelper.camelToId(StringHelper.trimEnd(this.constructor.name, 'Application'));
        }
        return this._baseName;
    }

    async init () {
        await super.init();
        this.baseUrl = this.mountPath === '/' ? this.mountPath : `${this.mountPath}/`;
    }

    getRoute (url) {
        if (this._route === undefined) {
            this._route = this.mountPath === '/' ? '' : this.mountPath;
        }
        return url ? `${this._route}/${url}` : this._route;
    }

    createFullName () {
        return this.getBaseName();
    }

    createRelativeName () {
        return '';
    }

    start () {
        this.attachHandlers();
        return this.createServer();
    }

    afterStart () {
        return this.trigger(this.EVENT_AFTER_START);
    }

    attachHandlers () {
        super.attachHandlers();
        this.mainEngine.attachChild(this.mountPath, this.engine);
    }

    createServer () {
        return new Promise((resolve, reject) => {
            this.server = this.mainEngine.createServer()
                .on('error', this.onServerError.bind(this, reject))
                .listen(this.getServerPort(), this.onServerStart.bind(this, resolve));
        });
    }

    getServerPort () {
        return this.serverPort || this.getConfig('port');
    }

    onServerError (reject, err) {
        this.log('error', 'Server error', err);
        reject(err);
    }

    onServerStart (resolve) {
        this.log('info', `Started ${this.fullName} as`, this.server.address());
        this.log('info', `Mounted ${this.fullName} as ${this.mountPath}`);
        this.afterStart().then(resolve);
    }
{'fraction_non_alphanumeric': 0.15411106328024107, 'fraction_numerical': 0.0017219113215669393, 'mean_word_length': 1.939278937381404, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '6394380', 'n_tokens_mistral': 1348, 'n_tokens_neox': 1305, 'n_words': 228}