diff --git a/.changeset/pr-828-2137854066.md b/.changeset/pr-828-2137854066.md new file mode 100644 index 000000000..6b2fd75bf --- /dev/null +++ b/.changeset/pr-828-2137854066.md @@ -0,0 +1,5 @@ + +--- +"fusion-project-portal": patch +--- +Improve loading logic in LegacyAppContainer, by loading app from new app api with proxy diff --git a/client/apps/legacyAppLoader/src/app-loader/legacy-interopt/LegacyAppContainer.ts b/client/apps/legacyAppLoader/src/app-loader/legacy-interopt/LegacyAppContainer.ts index 7560b2296..26a07c647 100644 --- a/client/apps/legacyAppLoader/src/app-loader/legacy-interopt/LegacyAppContainer.ts +++ b/client/apps/legacyAppLoader/src/app-loader/legacy-interopt/LegacyAppContainer.ts @@ -228,13 +228,13 @@ export class LegacyAppContainer extends EventEmitter { * assume if the manifest missing AppComponent or render, that loading is required */ - if (!AppComponent && !render) { - await this.#loadScript(key); + const manifest = this.#manifests.value[appKey] as unknown as AppManifest; + + if (!AppComponent && !render && manifest.build) { + await this.#loadScript(manifest); } await new Promise((resolve) => window.requestAnimationFrame(resolve)); - const manifest = this.#manifests.value[appKey] as unknown as AppManifest; - const currentApp = appProvider.current; if (currentApp && currentApp.appKey === appKey) { @@ -285,8 +285,9 @@ export class LegacyAppContainer extends EventEmitter { return this.updateComplete; } - async #loadScript(appKey: string): Promise { + async #loadScript(manifest: AppManifest): Promise { return new Promise((resolve, reject) => { + const { appKey, build } = manifest; const script = document.createElement('script'); script.async = true; script.id = appKey; @@ -296,8 +297,7 @@ export class LegacyAppContainer extends EventEmitter { script.addEventListener('load', () => resolve()); script.addEventListener('abort', () => reject()); script.addEventListener('error', () => reject()); - // Todo: Fix uri to mach the new structure - script.src = `${window['clientBaseUri']}/api/bundles/${appKey}.js`; + script.src = `/apps-proxy/bundles/apps/${appKey}/${build?.version}/${build?.entryPoint}`; }); } @@ -305,7 +305,7 @@ export class LegacyAppContainer extends EventEmitter { console.log('Updating'); this.#updateTask = new Promise((resolve, reject) => { this.#updateTask.state = 'pending'; - this.#appModules.app.getAllAppManifests().subscribe({ + this.#appModules.app.getAppManifests({ filterByCurrentUser: true }).subscribe({ complete: () => { this.#updateTask.state = 'fulfilled'; this.#lastUpdated = Date.now();