Basically a follow-up question from the one I've asked here: Kubernetes AKS ingress & MVC routing
I have a AKS environment including an ingress controller, an Angular SPA and an .NET Core Web API. Ingress routing with a subroute, either routing to the SPA or to the Web API.
rules:
- host: 09ab799fd5674c4594a5.centralus.aksapp.io
http:
paths:
- path: /ea/api
pathType: Prefix
backend:
service:
name: releaseeab-eab-chart
port:
number: {{ .Values.externalService.port }}
- path: /ea
pathType: Prefix
backend:
service:
name: releaseeaf-eaf-chart
port:
number: {{ .Values.externalService.port }}
In the MVC solution, I set the BasePath via ENV Variable to the appropriate path, which works very well, as all links etc. are also relative to this path, working perfectly fine with the routing.
The problem is that I can't do the same with Angular; I'm using a nginx rewrite to cut the path
location / {
rewrite ^/ea(/|$)(.*)$ /$2 last;
try_files $uri $uri/ =404;
}
This leads to the correct index.html, but all the script paths are still relative:
As Angular during the buildtime doesn't know anything about subpaths, it doesn't use the correct URL, not hitting the ingress. I know Angular can set the basepath, but I see a bit of a conceptual problem here: in the build, Angular should not be aware at all of anything regarding the environments it is hosted. I also really don't want to build different artifacts for different environments , but use the same Artifacts for all of them.
From what I see, one possibility would be to hack something during the deployment like here described https://nkpremices.com/dynamically-set-angular-env-variables-in-docker/, overruling the default Angular index.html, but this gets really messy.
I'm pretty sure I'm not the first person hosting a PWA behind an Ingress subpath. Is there a proper way to make this work without artifacts per environment?