diff --git a/charts/my-recipes-chart/templates/frontend-deployment.yaml b/charts/my-recipes-chart/templates/frontend-deployment.yaml index 8973e53..52edc17 100644 --- a/charts/my-recipes-chart/templates/frontend-deployment.yaml +++ b/charts/my-recipes-chart/templates/frontend-deployment.yaml @@ -25,13 +25,26 @@ spec: - containerPort: {{ .Values.frontend.service.targetPort }} name: http protocol: TCP - {{- with .Values.frontend.env }} + {{- /* compute API_BASE: prefer frontend.env.API_BASE, else use first ingress host */}} + {{- $apiBase := "" }} + {{- if .Values.frontend.env.API_BASE }} + {{- $apiBase = .Values.frontend.env.API_BASE }} + {{- else if .Values.ingress.hosts }} + {{- $firstHost := index .Values.ingress.hosts 0 }} + {{- $apiBase = printf "https://%s/api" $firstHost.host }} + {{- end }} env: + - name: API_BASE + value: {{ $apiBase | quote }} + {{- /* include any other env vars provided in values.frontend.env (skip API_BASE to avoid duplicate) */}} + {{- with .Values.frontend.env }} {{- range $key, $value := . }} + {{- if ne $key "API_BASE" }} - name: {{ $key }} value: {{ $value | quote }} {{- end }} - {{- end }} + {{- end }} + {{- end }} livenessProbe: httpGet: path: / diff --git a/charts/my-recipes-chart/values.yaml b/charts/my-recipes-chart/values.yaml index 76ad8f8..542968f 100644 --- a/charts/my-recipes-chart/values.yaml +++ b/charts/my-recipes-chart/values.yaml @@ -91,14 +91,17 @@ ingress: className: "nginx" annotations: cert-manager.io/cluster-issuer: "letsencrypt-prod" + nginx.ingress.kubernetes.io/rewrite-target: "/$2" + nginx.ingress.kubernetes.io/use-regex: "true" hosts: - host: recipes.local paths: - path: / pathType: Prefix backend: frontend - - path: /api - pathType: Prefix + # use a regex to capture and rewrite /api/... to /... on the backend + - path: /api(/|$)(.*) + pathType: ImplementationSpecific backend: backend tls: - secretName: recipes-tls