{"size": 947, "ext": "js", "max_stars_repo_path": "test/browser/utils/setup-server.js", "max_stars_repo_name": "Minkov/node-app", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test/browser/utils/setup-server.js", "max_issues_repo_name": "Minkov/node-app", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/browser/utils/setup-server.js", "max_forks_repo_name": "Minkov/node-app", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 27.0571428571, "max_line_length": 78, "alphanum_fraction": 0.4931362196}
const async = require('../../../utils/async');
const { getApp } = require('../../../app/app');
const dbUtils = require('../../shared/db.utils');

class Server {
    constructor(url, connectionString, port) {
        this.url = url;
        this.port = port;
        this.connectionString = connectionString;
    }

    start() {
        return async()
            .then(() => getApp({
                connectionString: this.connectionString,
                logsDirectory: this.logsDirectory,
            }))
            .then((app) => {
                this.app = app;
                return new Promise((resolve) => {
                    this.server = app.listen(this.port, resolve);
                });
            });
    }

    stop() {
        return async()
            .then(() => dbUtils.cleanUp(this.connectionString))
            .then(() => new Promise((resolve) => this.server.close(resolve)));
    }
}


module.exports = { Server };
