"use strict";

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

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

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

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

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

let options = (0, _utils.getOptions)();
let {
  cluster: {
    server
  }
} = options;
let app = (0, _express.default)();
let appPath = process.cwd();

let clusterConfigPath = _path.default.join(appPath, 'clusterConfig.js');

let config;

if (_fs.default.existsSync(clusterConfigPath)) {
  config = require(clusterConfigPath);
} else {
  throw new Error(`clusterConfig.js doen't exist under following path - ${clusterConfigPath}`);
}

app.get('/clusterhub/nodes', (req, res) => {
  res.send(JSON.stringify(config.cluster));
});
app.use('/clusterhub', _express.default.static(_path.default.join(__dirname, '..', '..', 'templates', 'clusterhub')));
app.listen(server.port, err => {
  if (err) {
    throw err;
  }

  (0, _utils.log)(`Listening at ${(0, _utils.getServerURL)(server, 'ht' + 'tp')}/clusterhub/`);
});