<p>I have a spring boot application which has some end points, ex: product/version</p>

<p>I deployed then the application to the K8s network and expose it out using Ingress as below: </p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: test-ingress
  annotations:
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
  rules:
  - http:
      paths:
      - path: /productApp
        backend:
          serviceName: productappservice
          servicePort: 80
</code></pre>

<p>I added a path to the ingress to have my application running under <code>my-host:8080/productApp/</code></p>

<p>In the <code>Deployment</code> configuration, I need to add the extra <code>context-path</code> to my application using <code>ConfigMap</code> to map with the URL that the ingress is exposing: </p>

<pre><code>---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: product-app
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: product-app
    spec:
      containers:
        - name: product-app
          image: my-docer-registry/product-app:latest
          imagePullPolicy: Always
          ports:
            - containerPort: 8080
          env:
            - name: server.servlet.context-path
              valueFrom:
                configMapKeyRef:
                  name: product-app-values
                  key: server.servlet.context-path

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: product-app-values
data:
   server.servlet.context-path: '/productApp'
</code></pre>

<p>So now my application is running under <code>my-host:8080/productApp/</code> and when I tried to call the API ex: <code>my-host:8080/productApp/product/version</code>, it worked fine.</p>

<p>The Problem came when I work with Swagger. I have swagger under: <code>my-host:8080/productApp/swagger-ui.html</code> and when I tried to call the <code>product/version</code> API, it returned <code>TypeError: Failed to fetch</code> . Then I realized that the host URL that swagger is sending request to is no longer <code>my-host:8080</code>, it was only <code>my-host</code>: </p>

<blockquote>
  <p>curl -X GET "<a href="http://my-host/productApp/product/version" rel="noreferrer">http://my-host/productApp/product/version</a>" -H
  "accept: application/json;charset=UTF-8"</p>
</blockquote>

<p>and here is the example json: </p>

<pre><code>{
    "swagger": "2.0",
    "info": {
        "version": "0.0.1-SNAPSHOT",
        "title": "Product App REST API"
    },
    "host": "my-host",
    "basePath": "/productApp",
    "tags": [{
        "name": "Product App API",
        "description": "REST API of Product App"
    },
    {
        "name": "version API",
        "description": "Version information of application and REST API"
    }],
    "paths": {
        .....
    }
}
</code></pre>

<p>What I expect here is the host URL should be <code>my-host:8080</code>, instead of only <code>my-host</code>, that's why the request in swagger is failed to sent. </p>

<p>Does anyone have an idea how to fix this problem. Thank you in advanced!</p>

Ock
<p>I encountered a similar problem when using <code>Istio Ingress</code>. I solved it by using an Nginx proxy and setting <code>X-Forwarded-Host</code> and <code>X-Forwarded-Port</code> request headers in Nginx config file to let Swagger know the correct address.</p>
