How to route to my UI application using root url / using spring cloud gateway

Viewed 14

I have react based UI application running on kubernetes with root contextPath (/). When I do kubectl port-forward svc/my-ui-app 8080:8080 and then launch the application on http://localhost:8080, everything works fine.

Now I want to use spring cloud gateway to route to my application. I configured the root url (/) and /apppath like below

spec:
  routes:
  - filters:
    - RewritePath=/apppath(?<segment>/?.*), $\{segment}
    predicates:
    - Path=/apppath/**
  - predicates:
    - Path=/
  service:
    name: my-ui-app

So my expection is to have http://my-domain and http://my-domain/apppath both to route to my ui application.

Whats happening is when I use http://my-domain/apppath, when the ui app internally refers to the index.js (and other image files), the url used for that evaluates to http://my-domain/apppath/index.js automatically and spring cloud gateway is able to load these files as it matches the route /apppath/** and is able to route to my application.

The problem is with the root url http://my-domain. When I hit this, the url to fetch the index.js (and images etc) evaluates to http://my-domain/index.js and spring cloud gateway does not know where to route it to as there is no route mapped for /index.js.

What do I need to do to make http://my-domain work without having to change the application code to have a contextPath explicitly set?

0 Answers
Related