diff --git a/docs/src/develop/plugins/server_plugin_api.md b/docs/src/develop/plugins/server_plugin_api.md index 7a12a4cc0..e0d3e5742 100644 --- a/docs/src/develop/plugins/server_plugin_api.md +++ b/docs/src/develop/plugins/server_plugin_api.md @@ -18,7 +18,7 @@ These functions are available via the `app` object passed to the plugin when it #### `app.getFeatures(enabed)` -Returns an object detailing the available APIs and Plugins. +Returns a Promise containing an object detailing the available APIs and Plugins. The `enabled` parameter is optional and has the following values: - `undefined` (not provided): list all features @@ -27,7 +27,7 @@ The `enabled` parameter is optional and has the following values: _Example:_ ```javascript -let features = app.getFeatures(); +const features = await app.getFeatures(); { "apis": [ diff --git a/src/index.ts b/src/index.ts index 574a7d519..19e508907 100644 --- a/src/index.ts +++ b/src/index.ts @@ -132,9 +132,25 @@ class Server { // feature detection app.getFeatures = async (enabled?: boolean) => { + const checkPMStarted = (): Promise => { + return new Promise((resolve) => { + setImmediate(() => { + resolve(typeof app.getPluginsList === 'function') + }) + }) + } + const maxTries = 10 + let tries = 0 + let pmStarted = false + + while (!pmStarted && tries < maxTries) { + tries++ + pmStarted = await checkPMStarted() + } + const plugins = pmStarted ? await app.getPluginsList(enabled) : [] return { apis: enabled === false ? [] : app.apis, - plugins: await app.getPluginsList(enabled) + plugins: plugins } }