<commit_before>const fs = require('../../core/fs.js');
var {canonicalHost} = require('../../utils/host.js');
var utils = require('../../utils/utils.js');
var Server = require('./server.js');
const opn = require('opn');

require('ejs');
const Templates = {
  embark_building_placeholder: require('./templates/embark-building-placeholder.html.ejs')
};

class WebServer {
  constructor(embark, options) {
    this.embark = embark;
    this.logger = embark.logger;
    this.events = embark.events;
    this.buildDir = embark.config.buildDir;
    this.plugins = options.plugins;
    this.webServerConfig = embark.config.webServerConfig;
    if (!this.webServerConfig.enabled) {
      return;
    }

    this.host = this.webServerConfig.host;
    this.port = parseInt(this.webServerConfig.port, 10);
    this.enableCatchAll = this.webServerConfig.enableCatchAll === true;
    this.enableCatchAll = false; // FIXME when true, some Requests end up failing (eg: process-logs)

    this.events.request('processes:register', 'webserver', {
      launchFn: (cb) => { this.server.start(cb); },
      stopFn: (cb) => { this.server.stop(cb); }
    });

    this.events.emit("status", __("Starting Server"));

    this.server = new Server({
      logger: this.logger,
      buildDir: this.buildDir,
      events: this.events,
      host: this.host,
      port: this.port,
      plugins: this.plugins,
      openBrowser: this.webServerConfig.openBrowser,
      protocol: this.webServerConfig.protocol,
      certOptions : this.webServerConfig.certOptions
    });

    this.listenToCommands();
    this.registerConsoleCommands();

    this.events.on('webserver:config:change', () => {
      this.embark.config.webServerConfig = null;
      this.embark.config.loadWebServerConfigFile();
      this.webServerConfig = this.embark.config.webServerConfig;
      this.host = this.webServerConfig.host;
      this.port = this.webServerConfig.port;
      this.server.host = this.host;
      this.server.port = this.port;
      this.server.protocol = this.webServerConfig.protocol;
      this.server.certOptions =  this.webServerConfig.certOptions;<commit_msg>Fixes webserver protocol<commit_after>const fs = require('../../core/fs.js');
var {canonicalHost} = require('../../utils/host.js');
var utils = require('../../utils/utils.js');
var Server = require('./server.js');
const opn = require('opn');

require('ejs');
const Templates = {
  embark_building_placeholder: require('./templates/embark-building-placeholder.html.ejs')
};

class WebServer {
  constructor(embark, options) {
    this.embark = embark;
    this.logger = embark.logger;
    this.events = embark.events;
    this.buildDir = embark.config.buildDir;
    this.plugins = options.plugins;
    this.webServerConfig = embark.config.webServerConfig;
    if (!this.webServerConfig.enabled) {
      return;
    }

    this.host = this.webServerConfig.host;
    this.protocol = this.webServerConfig.protocol;
    this.port = parseInt(this.webServerConfig.port, 10);
    this.enableCatchAll = this.webServerConfig.enableCatchAll === true;
    this.enableCatchAll = false; // FIXME when true, some Requests end up failing (eg: process-logs)

    this.events.request('processes:register', 'webserver', {
      launchFn: (cb) => { this.server.start(cb); },
      stopFn: (cb) => { this.server.stop(cb); }
    });

    this.events.emit("status", __("Starting Server"));

    this.server = new Server({
      logger: this.logger,
      buildDir: this.buildDir,
      events: this.events,
      host: this.host,
      port: this.port,
      plugins: this.plugins,
      openBrowser: this.webServerConfig.openBrowser,
      protocol: this.webServerConfig.protocol,
      certOptions : this.webServerConfig.certOptions
    });

    this.listenToCommands();
    this.registerConsoleCommands();

    this.events.on('webserver:config:change', () => {
      this.embark.config.webServerConfig = null;
      this.embark.config.loadWebServerConfigFile();
      this.webServerConfig = this.embark.config.webServerConfig;
      this.protocol = this.webServerConfig.protocol;
      this.host = this.webServerConfig.host;
      this.port = this.webServerConfig.port;
      this.server.host = this.host;
      this.server.port = this.port;
      this.server.protocol = this.webServerConfig.protocol;
      this.server.certOptions =  this.webServerConfig.certOptions;
{'fraction_non_alphanumeric': 0.1433462679753481, 'fraction_numerical': 0.0009130335539831089, 'mean_word_length': 3.342913776015857, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '2118318', 'n_tokens_mistral': 1347, 'n_tokens_neox': 1325, 'n_words': 227}