moleculerjs / moleculer-web

:earth_africa: Official API Gateway service for Moleculer framework
http://moleculer.services/docs/moleculer-web.html
MIT License
291 stars 119 forks source link

[FR] Notify when regenerateAllAutoAliases is ended #288

Closed DenisFerrero closed 2 years ago

DenisFerrero commented 2 years ago

Hi, I think that would be useful to notify with an event to the other services when the API is being updated after using regenerateAllAutoAliases. For example, when generating the OpenAPI schema would be useful to generate the schema just the first time that is requested and then cache it, and regenerate it again when the API change. At the moment I added this to my API gateway so it would work as I wanted to

created () {
  const debounceTime = this.settings.debounceTime > 0 ? parseInt(this.settings.debounceTime) : 500;
  // Update the library method regenerateAllAutoAliases by notifying with an event when the function is ended
  this.regenerateAllAutoAliases = _.debounce(() => {
      this.routes.forEach(route => route.opts.autoAliases && this.regenerateAutoAliases(route));
      this.broker.emit('api.updated');
  }, debounceTime);
}