How to wire a React UI behind a Spring Cloud Gateway? (NOT using Zuul)

Viewed 907

The problem I am trying to solve is very common:

 User
  |
Gateway
  /\
UI   Protected Resource/API Server

However, I have been searching for a while now and all the examples I see for wiring a UI behind Spring Cloud Gateway are using the OLD Zuul stack. As far as using the new Spring Cloud Gateway, I only saw a way to rewrite path or forward requests to other APIs. When trying that mechanism on UI it doesn't work (seems like it's just executing whatever get/post/etc against the UI instead of redirecting to it). So is there a way to get something like this to work as expected?

@Bean
public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
    return builder..routes()
            .route("path_route", r -> r.path("/")
                    .uriuri("test.com")
                    .build();
}

Eventually I would like to store sessionId in cookies for frontend and on the gateway side those sessions are cached in Redis so request will be validated then redirected to UI but that's probably unrelated to the redirection problem

1 Answers

I ended up with main and sub domains. The main for UI and the subdomain for the API. The login button on UI takes you to /login. That will complete the login process and then store the session details appropriately, then redirect back to the UI main domain.

If anyone would like more details, feel free to reply here and I can assist further as needed

Related