2

I have an application build using Single-Spa and it consist of:

  • Root Config App (hosted on http://localhost:3000)
  • App1 (Angular application hosted on http://localhost:3001)

App1 has a dependency (npm package) Dep1. Dep1 provides img-preview.png file and PreviewComponent (which I use in App1) with this html:

<img src="/assets/images/img-preview.png">

When I open my app (by Root Config App) it tries to load the img-preview.png file from http://localhost:3000/assets/images/img-preview.png, but it won't work, because the file is served on http://localhost:3001.

For the assets that are directly under App1 I use the assetUrl helper method provided by single-spa-angular(angular-assets). However I cannot find any solution to load assets that are defined and used within npm dependencies. I cannot modify Dep1. The only way that seems feaseable is to replace Dep1 with my custom code, but that's just ludicrous.

Does anyone know how to solve it?

conrisc
  • 43
  • 1
  • 5
  • Your question doesn't really make sense; when you have an app dependency it doesn't mean it is served on a different host (different port in this case). You should install the dependency properly with a package manager like npm and then you will be able to use the assets from within the same origin. – Wilt Jan 24 '23 at 17:55
  • On a side note, SPA means single page application. So *"Single-Spa application"* means literally: *"Single single page application application"*. – Wilt Jan 24 '23 at 17:57
  • "Single-Spa" is the name of the framework I'm using, it's a solution for Microfrontend. Yes, the dependency **Dep1** is installed within App1, so since it's a part of this app, it's also bundled together with it and hosted on http://localhost:3001, but the Root Config App is served on http://localhost:3000 and it resolves all assets (even those from App1) using localhost:3000 not 3001 - that's why it cannot access them. – conrisc Jan 24 '23 at 18:43
  • 1
    Learned something new today, never heard of that framework. Also I don't have the proper knowledge to help you any further with this issue. Hope you get some help of someone else familiar with this setup. – Wilt Jan 24 '23 at 19:30
  • 1
    Yeah, the description was a bit misleading, I'll try to be more precise in the future. Thanks anyway ;) – conrisc Jan 24 '23 at 19:35

0 Answers0