<p>So I've set up my SPA in Go using Gorilla/Mux but I want to run it on different routes so I can connect two of my Kubernetes services together (2 different SPAs). <em>could it be that I have to change my kubernetes service to /stock instead?</em></p>
<p>My one service runs on the regular path &quot;/&quot; and I want to add a second service so that when the user types in &quot;https://URL/stock&quot; my second SPA is served (want 2nd spa to run on /stock)</p>
<p>I know one way would just be to merge my code and whatnot into my first service, but I was wondering if I could do it this way?</p>
<p><strong>main.go</strong></p>
<pre class="lang-golang prettyprint-override"><code>type spaHandler struct {
    staticPath string
    indexPath  string
}

func (h spaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
    path, err := filepath.Abs(r.URL.Path)
    if err != nil {
        http.Error(w, err.Error(), http.StatusBadRequest)
        return
    }

    path = filepath.Join(h.staticPath, r.URL.Path)

    _, err = os.Stat(path)
    if os.IsNotExist(err) {
        http.ServeFile(w, r, filepath.Join(h.staticPath, h.indexPath))
        return
    } else if err != nil {
        http.Error(w, err.Error(), http.StatusInternalServerError)
        return
    }

    http.FileServer(http.Dir(h.staticPath)).ServeHTTP(w, r)
}


func main() {
    router := mux.NewRouter().StrictSlash(true)
    //Serve Other Routes Above PathPrefix
    router.HandleFunc(&quot;/api/findStock&quot;, findStock)
    spa := spaHandler{staticPath: &quot;./stock/build&quot;, indexPath: &quot;index.html&quot;}
    router.PathPrefix(&quot;/&quot;).Handler(spa) &lt;------ any way to serve on /stock???

    svr := &amp;http.Server{
        Handler: router,
        Addr:    &quot;:8080&quot;,
        WriteTimeout: 15 * time.Second,
        ReadTimeout:  15 * time.Second,
    }

    log.Fatal(svr.ListenAndServe())
}
</code></pre>
<p><strong>App.js</strong></p>
<pre class="lang-js prettyprint-override"><code>class App extends Component {
  render(){
    return (
        &lt;Router&gt;
          &lt;div&gt;
            &lt;section&gt;
              &lt;NavBar/&gt;
              &lt;Switch&gt;
                &lt;Route exact path='/'  component={Home}/&gt;
              &lt;/Switch&gt;
            &lt;/section&gt;
          &lt;/div&gt;
        &lt;/Router&gt;
    );
  }
}

export default App;
</code></pre>
<p>I know I can change the path to /stock in App.js but when I got to localhost:8080/ it still shows my navbar on it</p>
<p><strong>UPDATED</strong></p>
<p><strong>ingress.yaml</strong></p>
<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/from-to-www-redirect: &quot;true&quot;
    nginx.ingress.kubernetes.io/rewrite-target: /
  name: ingress
spec:
  rules:
   - host: www.url.com
     http:
       paths:
         - backend:
             serviceName: service1
             servicePort: 80
           path: /
         - backend:
             serviceName: stockService
             servicePort: 80
           path: /stock

</code></pre>
<p>So when I go to the /stock endpoint, I'm getting</p>
<p>The resource from &quot;www.url.com//static/css/2.d9ad5f5c.chunk.css&quot; was blocked due to MIME type (“text/plain”) mismatch (X-Content-Type-Options: nosniff)</p>
<p>I assume this is because my Stock Service default path is set to / in main.go so it's trying to serve files from there, but on the web I'm trying to access it from /stock</p>
<p><strong>NEW UPDATE/FIX</strong></p>
<p><strong>main.go</strong></p>
<pre><code>func main() {
    router := mux.NewRouter()
    //Serve Other Routes Above PathPrefix
    router.HandleFunc(&quot;/api/findStock&quot;, findStock)
    spa := spaHandler{staticPath: &quot;./stock/build&quot;, indexPath: &quot;index.html&quot;}
    router.PathPrefix(&quot;/stock&quot;).Handler(http.StripPrefix(&quot;/stock&quot;, spa)) &lt;-- UPDATED

    svr := &amp;http.Server{
        Handler:      router,
        Addr:         &quot;:8080&quot;,
        WriteTimeout: 15 * time.Second,
        ReadTimeout:  15 * time.Second,
    }

    log.Fatal(svr.ListenAndServe())
}
</code></pre>
<p><strong>App.js</strong></p>
<pre><code>class App extends Component {
  render(){
    return (
        &lt;Router&gt;
          &lt;div&gt;
            &lt;section&gt;
              &lt;NavBar/&gt;
              &lt;Switch&gt;
                &lt;Route exact path='/stock'  component={Home}/&gt;
              &lt;/Switch&gt;
            &lt;/section&gt;
          &lt;/div&gt;
        &lt;/Router&gt;
    );
  }
}

export default App;
</code></pre>
<p><strong>package.json</strong></p>
<pre><code>{
  &quot;homepage&quot;: &quot;stock&quot;, &lt;---- This was newly added to the top of my file
  &quot;name&quot;: &quot;stock&quot;,
  &quot;version&quot;: &quot;0.1.0&quot;,
}
</code></pre>
<p>I'm still using ingress to access my second service</p>

<p>Although doable, if you are using Kubernetes it seems hacky to do it the way you are doing it. Why not use 2 <a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">Kubernetes services</a> and then connect to them through an <a href="https://kubernetes.io/docs/concepts/services-networking/ingress/" rel="nofollow noreferrer">Ingress</a> controller like <a href="https://kubernetes.io/docs/concepts/services-networking/ingress/" rel="nofollow noreferrer">Nginx</a>? For example:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: minimal-ingress
spec:
  rules:
  - http:
      paths:
      - path: /stock
        pathType: Exact
        backend:
          service:
            name: stock-service
            port:
              number: 80
      - path: /
        pathType: Prefix
        backend:
          service:
            name: first-service
            port:
              number: 80

</code></pre>
<p>✌️</p>
