packages/api-gateway/src/index.js
function loadEndpoints() {
  // Shortcut if endpoints already have been loaded
  if (endpoints !== undefined) {
    return Promise.resolve(endpoints);
  }

  const endpointSpecsPath = path.join(process.cwd(), plugin.config.endpointsPath);

  return plugin.myrmex.fire('beforeEndpointsLoad')
  .spread(() => {
    const endpointPromises = [];
    file.walkSync(endpointSpecsPath, (dirPath, dirs, files) => {
      // We are looking for directories that have the name of an HTTP method
      const subPath = dirPath.substr(endpointSpecsPath.length);
      const resourcePathParts = subPath.split(path.sep);
      const method = resourcePathParts.pop();
      if (plugin.httpMethods.indexOf(method) === -1) { return; }

      // We construct the path to the resource
      const resourcePath = resourcePathParts.join('/');

      endpointPromises.push(loadEndpoint(endpointSpecsPath, resourcePath, method));
    });
    return Promise.all(endpointPromises);
  })
  .then(endpoints => {
    return plugin.myrmex.fire('afterEndpointsLoad', endpoints);
  })
  .spread(loadedEndpoints => {
    endpoints = loadedEndpoints;
    return Promise.resolve(endpoints);
  })
  .catch(e => {
    if (e.code === 'ENOENT' && path.basename(e.path) === path.basename(plugin.config.endpointsPath)) {
      return Promise.resolve([]);
    }
    Promise.reject(e);
  });
}
function loadEndpoints() {
  // Shortcut if endpoints already have been loaded
  if (endpoints !== undefined) {
    return Promise.resolve(endpoints);
  }

  const endpointSpecsPath = path.join(process.cwd(), plugin.config.endpointsPath);

  return plugin.myrmex.fire('beforeEndpointsLoad')
  .spread(() => {
    const endpointPromises = [];
    file.walkSync(endpointSpecsPath, (dirPath, dirs, files) => {
      // We are looking for directories that have the name of an HTTP method
      const subPath = dirPath.substr(endpointSpecsPath.length);
      const resourcePathParts = subPath.split(path.sep);
      const method = resourcePathParts.pop();
      if (plugin.httpMethods.indexOf(method) === -1) { return; }

      // We construct the path to the resource
      const resourcePath = resourcePathParts.join('/');

      endpointPromises.push(loadEndpoint(endpointSpecsPath, resourcePath, method));
    });
    return Promise.all(endpointPromises);
  })
  .then(endpoints => {
    return plugin.myrmex.fire('afterEndpointsLoad', endpoints);
  })
  .spread(loadedEndpoints => {
    endpoints = loadedEndpoints;
    return Promise.resolve(endpoints);
  })
  .catch(e => {
    if (e.code === 'ENOENT' && path.basename(e.path) === path.basename(plugin.config.endpointsPath)) {
      return Promise.resolve([]);
    }
    Promise.reject(e);
  });
}
function loadEndpoints ( ) { // Shortcut if endpoints already have been loaded if ( endpoints !== undefined ) { return Promise . resolve ( endpoints ) ; } const endpointSpecsPath = path . join ( process . cwd ( ) , plugin . config . endpointsPath ) ; return plugin . myrmex . fire ( 'beforeEndpointsLoad' ) . spread ( ( ) => { const endpointPromises = [ ] ; file . walkSync ( endpointSpecsPath , ( dirPath , dirs , files ) => { // We are looking for directories that have the name of an HTTP method const subPath = dirPath . substr ( endpointSpecsPath . length ) ; const resourcePathParts = subPath . split ( path . sep ) ; const method = resourcePathParts . pop ( ) ; if ( plugin . httpMethods . indexOf ( method ) === - 1 ) { return ; } // We construct the path to the resource const resourcePath = resourcePathParts . join ( '/' ) ; endpointPromises . push ( loadEndpoint ( endpointSpecsPath , resourcePath , method ) ) ; } ) ; return Promise . all ( endpointPromises ) ; } ) . then ( endpoints => { return plugin . myrmex . fire ( 'afterEndpointsLoad' , endpoints ) ; } ) . spread ( loadedEndpoints => { endpoints = loadedEndpoints ; return Promise . resolve ( endpoints ) ; } ) . catch ( e => { if ( e . code === 'ENOENT' && path . basename ( e . path ) === path . basename ( plugin . config . endpointsPath ) ) { return Promise . resolve ( [ ] ) ; } Promise . reject ( e ) ; } ) ; }
Load all Endpoint specifications
@returns {Promise<[Endpoints]>} - the promise of an array containing all endpoints
Load all Endpoint specifications