angular app giving mime errors and fails to load on browser after deployed on kubernetes ingress

8/22/2019

Issue is that my css & js angular production build files are not getting picked properly , from the browser logs what i understood is that js and cs not loaded because its MIME type, “text/html”, is not “text/css”.

Providing screenshot of errors on browser console.

screenshot link below enter image description here

enter image description here

Below is my nginx configuration file

server {
  listen 80;

  root   /usr/share/nginx/html;
  index  index.html index.htm;
  include /etc/nginx/mime.types;

  gzip on;
  gzip_min_length 1000;
  gzip_proxied expired no-cache no-store private auth;
  gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;


  location / {
    try_files $uri $uri/ /index.html;
  }

}

I have deployed the below ingress yaml

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: test-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/force-ssl-redirect: "false"
spec:
  rules:
  - http:
      paths:
      - path: /test
        backend:
          serviceName: testapp
          servicePort: 80
      - path: /assets
        backend:
          serviceName: testapp
          servicePort: 80

What Im trying to achieve is I should be able to load my application on ingress path (/test) , but fails to display . When I try without a ingress path(i.e below), it works properly: could you please help me out what im doing wrong

-- Vinay Mohan
angular
kubernetes
kubernetes-ingress
nginx

2 Answers

9/9/2019

Posting as Community answer to better visibility in future reference. Solution was found based on @John comments.

Issue: Cannot connect to resource styles.0e4338761429b4eb16ac.css.
How resource was requested: [Nginx-controller-ip]/styles.0e4338761429b4eb16ac.css

OP's Ingress manifest contains 2 endpoints (/test/* and /assets/ *).

Ingress was looking for file styles.0e4338761429b4eb16ac.css in endpoint folders. As it cannot find it (because file was in main folder, not in endpoints) it returned 404 NOT FOUND.

Solution: To reach this file it must be in one of folders from Ingress YAML (as both was reffered to the same service serviceName: testapp).

-- PjoterS
Source: StackOverflow

5/6/2020

I have managed to fix the issue by changing in tsconfig.json

target:'es5'`

instead of

target:'es2015'`
-- Sachin Mishra
Source: StackOverflow