#!/usr/bin/env node
"use strict";

var _readOptions = require("../../schemas/readOptions");

var _corsHandling = require("./corsHandling");

var _getServerURL = require("./getServerURL");

var _initExpressApp = require("./initExpressApp");

var _mockApiHandler = require("./mockApiHandler");

var _startHttpServer = require("./startHttpServer");

function getMockServerExtras(options) {
  const {
    separateSeverPort
  } = options.mockServer;
  const httpPort = Number(separateSeverPort);
  const httpUrl = (0, _getServerURL.getServerUrl)({
    domain: 'localhost',
    port: httpPort,
    protocol: 'http'
  });
  return {
    httpPort,
    httpUrl,
    isHttps: false
  };
}

const options = (0, _readOptions.getOptions)();
const {
  mockEntryFile
} = options.mockServer;
options.serverExtras = getMockServerExtras(options);
const app = (0, _initExpressApp.initExpressApp)();
(0, _corsHandling.corsHandling)(app, options);
(0, _startHttpServer.startHttpServer)(app, options);
(0, _mockApiHandler.handleMockApi)(mockEntryFile, app);