"use strict";

var _express = _interopRequireDefault(require("express"));

var _fs = _interopRequireDefault(require("fs"));

var _path = _interopRequireDefault(require("path"));

var _utils = require("../utils");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

let options = (0, _utils.getOptions)();
let {
  app: {
    server: {
      mockPort
    }
  }
} = options;
const app = (0, _express.default)();
app.use(_express.default.json());
app.use(_express.default.urlencoded({
  extended: true
}));
let appPath = process.cwd();

let mockServerPath = _path.default.join(appPath, 'mockapi', 'index.js');

if (_fs.default.existsSync(mockServerPath)) {
  let mockServer = require(mockServerPath);

  mockServer(app);
} else {
  (0, _utils.log)('You must export a function from mockapi folder by only we can provide mock api hook');
}

app.listen(mockPort, err => {
  if (err) {
    (0, _utils.log)('error', err);
  } else {
    (0, _utils.log)(`mock server listening port: ${mockPort}`);
  }
});