all files / dist/satellites/ id.js

75.47% Statements 40/53
54.17% Branches 13/24
100% Functions 9/9
69.44% Lines 25/36
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122                                                                                                                                                                                                 
'use strict';
 
Object.defineProperty(exports, "__esModule", {
  value: true
});
 
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; Eif ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { Eif (protoProps) defineProperties(Constructor.prototype, protoProps); Iif (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
 
var _yargs = require('yargs');
 
var _cluster = require('cluster');
 
var _cluster2 = _interopRequireDefault(_cluster);
 
var _utils = require('../utils');
 
var _utils2 = _interopRequireDefault(_utils);
 
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 
function _classCallCheck(instance, Constructor) { Iif (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
 
/**
 * Setup the server ID.
 *
 * This ID, can be configured using:
 * - the 'api.config.general.id' configuration;
 * - '--title' option on the command line;
 * - 'STELLAR_TITLE' environment variable;
 * - or one can be generated automatically using the external server IP.
 */
 
var _class = function () {
  function _class() {
    _classCallCheck(this, _class);
 
    this.loadPriority = 100;
    this.startPriority = 2;
  }
 
  /**
   * Load priority.
   *
   * @type {number}
   */
 
 
  /**
   * Start priority.
   *
   * @type {number}
   */
 
 
  _createClass(_class, [{
    key: 'load',
 
 
    /**
     * Initializer load functions.
     *
     * @param api   API reference.
     * @param next  Callback.
     */
    value: function load(api, next) {
      Iif (_yargs.argv.title) {
        api.id = _yargs.argv.title;
      } else Iif (process.env.STELLAR_TITLE) {
        api.id = process.env.STELLAR_TITLE;
      } else Iif (!api.config.general.id) {
        // get servers external IP
        var externalIP = _utils2.default.getExternalIPAddress();
 
        if (externalIP === false) {
          var message = ' * Error fetching this host external IP address; setting id base to \'stellar\'';
 
          try {
            api.log(message, 'crit');
          } catch (e) {
            console.log(message);
          }
        }
 
        api.id = externalIP;
        if (_cluster2.default.isWorker) {
          api.id += ':' + process.pid;
        }
      } else {
        api.id = api.config.general.id;
      }
 
      // save Stellar version
      api.stellarVersion = require('../../package.json').version;
 
      // finish the initializer load
      next();
    }
 
    /**
     * Initializer start function.
     *
     * @param api   API reference.
     * @param next  Callback.
     */
 
  }, {
    key: 'start',
    value: function start(api, next) {
      // print out the server ID
      api.log('server ID: ' + api.id, 'notice');
 
      // finish the initializer start
      next();
    }
  }]);
 
  return _class;
}();
 
exports.default = _class;
//# sourceMappingURL=id.js.map