<p>I've been working on this for a while and can't seem to get anywhere.</p>

<p>Basically, I have an ingress controller for a microservice that has a URL of:</p>

<pre><code>- path: /client/?(.*)
  backend:
    serviceName: client-cluster-ip-service
    servicePort: 3000
</code></pre>

<p>However, when I navigate to <code>192.168.64.4/client</code> (this is the <code>minikube ip</code>) I don't see anything because the URL <code>npm start</code> is using for the static files is <code>/static</code>. I need to change it to <code>/client/static</code>. </p>

<p>Is that possible?</p>

<p>I know that <code>homepage: "/client"</code> is not an option since that is just for production. This is in CRA so I'd like to avoid ejecting it.</p>

<p>EDIT:</p>

<p>Added my current <code>ingress.yaml</code>:</p>

<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
  name: ingress-service
  namespace: default
spec:
  rules:
    - http:
        paths:
          - path: /client/?(.*)
            backend:
              serviceName: client-cluster-ip-service
              servicePort: 3000
          - path: /api/?(.*)
            backend:
              serviceName: server-cluster-ip-service
              servicePort: 5000

</code></pre>

<p>The <code>/api</code> route works fine because Django has a built in way of handling prefixed paths. Without doing this, it will not serve <code>static</code> files properly particularly for the <code>admin</code> portal:</p>

<pre><code>FORCED_SCRIPT_NAME = '/api'
STATIC_URL = '/api/static/'
</code></pre>

<p>ReactJS, apparently does not <em>in development</em>. You can manually navigate to <code>/client/static/js/bungle.js</code> and see the <code>.js</code> there. So somehow <code>/client</code> needs to be prefixed to the <code>/static/</code> path.</p>

<p>I did try changing the following:</p>

<pre><code>nginx.ingress.kubernetes.io/rewrite-target: /$2
</code></pre>

<p>This created some odd behavior. </p>

<ul>
<li>On the <code>/client</code>, still the same issue, but can't find the <code>/static</code> files at any location (e.g., <code>/client/static</code>, <code>/static</code>, etc.)</li>
<li>On the <code>/api</code>, can't get it to serve anything with, or without, <code>FORCE_SCRIPT_NAME</code>. The ingress is getting into the Django, but says it can't match any of the routes, which is incredibly strange.</li>
</ul>

<p>Use the rewrite annotations in your ingress definition, I think that in your case it would be something like this:</p>

<pre><code>annotations:
  nginx.ingress.kubernetes.io/rewrite-target: /$2
</code></pre>

<p>The $2 gets replaces with the capture (.*) of the match, then if you try to access /client/static the resulting rewrite would be /static ... this should work in theory, give it a try!
If this didn't work let me know to try to figure out why</p>

<p>Here is a similar definition for my resources as well, not exactly as your case, but I am using the rewrite and it is working here.</p>

<pre><code>apiVersion: v1
kind: Ingress
metadata:
  name: proxy-ingress
  namespace: repoflow-s3-proxy-demo
annotations:
  nginx.ingress.kubernetes.io/rewrite-target: /resources.repoflow.com/resources/$2
  nginx.ingress.kubernetes.io/upstream-vhost: s3.amazonaws.com
spec:
  rules:
  - host: s3-proxy.repoflow.com
    http:
      paths:
        - path: /resources(/|$)(.*)
          backend:
            serviceName: resources-external-service
            servicePort: 80
</code></pre>
