packages/api-gateway/src/index.js
function loadApi(apiSpecPath, identifier) {
  return plugin.myrmex.fire('beforeApiLoad', apiSpecPath, identifier)
  .spread((apiSpecPath, identifier) => {
    // Because we use require() to get the spec, it could either be a JSON file
    // or the content exported by a node module
    // But because require() caches the content it loads, we clone the result to avoid bugs
    // if the function is called twice
    const apiSpec = _.cloneDeep(require(apiSpecPath));
    apiSpec['x-myrmex'] = apiSpec['x-myrmex'] || {};

    // Lasy loading because the plugin has to be registered in a Myrmex instance before requiring ./endpoint
    const Api = require('./api');
    const api = new Api(apiSpec, identifier);

    // This event allows to inject code to alter the API specification
    return plugin.myrmex.fire('afterApiLoad', api);
  })
  .spread(api => {
    return api.init();
  });
}
function loadApi(apiSpecPath, identifier) {
  return plugin.myrmex.fire('beforeApiLoad', apiSpecPath, identifier)
  .spread((apiSpecPath, identifier) => {
    // Because we use require() to get the spec, it could either be a JSON file
    // or the content exported by a node module
    // But because require() caches the content it loads, we clone the result to avoid bugs
    // if the function is called twice
    const apiSpec = _.cloneDeep(require(apiSpecPath));
    apiSpec['x-myrmex'] = apiSpec['x-myrmex'] || {};

    // Lasy loading because the plugin has to be registered in a Myrmex instance before requiring ./endpoint
    const Api = require('./api');
    const api = new Api(apiSpec, identifier);

    // This event allows to inject code to alter the API specification
    return plugin.myrmex.fire('afterApiLoad', api);
  })
  .spread(api => {
    return api.init();
  });
}
function loadApi ( apiSpecPath , identifier ) { return plugin . myrmex . fire ( 'beforeApiLoad' , apiSpecPath , identifier ) . spread ( ( apiSpecPath , identifier ) => { // Because we use require() to get the spec, it could either be a JSON file // or the content exported by a node module // But because require() caches the content it loads, we clone the result to avoid bugs // if the function is called twice const apiSpec = _ . cloneDeep ( require ( apiSpecPath ) ) ; apiSpec [ 'x-myrmex' ] = apiSpec [ 'x-myrmex' ] || { } ; // Lasy loading because the plugin has to be registered in a Myrmex instance before requiring ./endpoint const Api = require ( './api' ) ; const api = new Api ( apiSpec , identifier ) ; // This event allows to inject code to alter the API specification return plugin . myrmex . fire ( 'afterApiLoad' , api ) ; } ) . spread ( api => { return api . init ( ) ; } ) ; }
Load an API specification
@param {string} apiSpecPath - the full path to the specification file
@param {string} OPTIONAL identifier - a human readable identifier, eventually
configured in the specification file itself
@returns {Promise<Api>} - the promise of an API instance
Load an API specification