diff --git a/src/backend/src/Extension.js b/src/backend/src/Extension.js index a5d4efa0f..f40a21c46 100644 --- a/src/backend/src/Extension.js +++ b/src/backend/src/Extension.js @@ -218,6 +218,14 @@ class Extension extends AdvancedBase { methods: ['POST'], }); } + + use (...args) { + this.ensure_service_(); + this.service.expressThings_.push({ + type: 'router', + value: args, + }); + } get preinit() { return (function (callback) { diff --git a/src/backend/src/ExtensionService.js b/src/backend/src/ExtensionService.js index 626d11482..7ca52e6ec 100644 --- a/src/backend/src/ExtensionService.js +++ b/src/backend/src/ExtensionService.js @@ -36,7 +36,7 @@ class ExtensionServiceState extends AdvancedBase { this.extension = a[0].extension; - this.endpoints_ = []; + this.expressThings_ = []; // Values shared between the `extension` global and its service this.values = new Context(); @@ -66,7 +66,7 @@ class ExtensionServiceState extends AdvancedBase { ...(options.subdomain ? { subdomain: options.subdomain } : {}), }); - this.endpoints_.push(endpoint); + this.expressThings_.push({ type: 'endpoint', value: endpoint }); } } @@ -77,7 +77,7 @@ class ExtensionServiceState extends AdvancedBase { */ class ExtensionService extends BaseService { _construct () { - this.endpoints_ = []; + this.expressThings_ = []; } async _init (args) { this.state = args.state; @@ -170,8 +170,15 @@ class ExtensionService extends BaseService { ['__on_install.routes'] (_, { app }) { if ( ! this.state ) debugger; - for ( const endpoint of this.state.endpoints_ ) { - endpoint.attach(app); + for ( const thing of this.state.expressThings_ ) { + if ( thing.type === 'endpoint' ) { + thing.value.attach(app); + continue; + } + if ( thing.type === 'router' ) { + app.use(...thing.value); + continue; + } } }