Blank Pages when accessing services through Spring Cloud Gateway

Viewed 137

As a continuation of my learning of the Spring Cloud Gateway, I have created a small microservice (from Spring Boot) that serves web pages. This microservice is simple enough: it uses an application.properties file that contains the following:

server.port=8091
spring.resources.static-locations=classpath:/public/

The microservice has an index page in the resources folder, along with some style and other resources:

resources/public/index.html
resources/public/css/styling.css
resources/public/graphics/<pretty graphics files>

The Spring Cloud Gateway application uses a fairly straightforward routing configuration:

@Configuration
public class RouteConfig
{

   @Bean
   public RouteLocator gatewayRoutes(RouteLocatorBuilder routeLocatorBuilder)
   {
      return routeLocatorBuilder.routes()
             .route("webdisplay",route-> route.path("/webdisplay/**").uri("localhost:8091"))
             .build();
   }
}

The Spring Cloud Gateway application listens on Port 8080.

When I access the simple microservice diectly:

http://localhost:8091

The index.html page is displayed as normal. Unfortunately, when I access the microservice through the Gateway:

http://localhost:8080/webdisplay

I get a blank page!

The page is blank, and the page source has nothing )(no HTML, nothing!). When using my browser's network debugger, I am seeing a response code of 200 with headers showing that HTML and other related web content is accepted. The HTML, however, is not actually getting to the browser.

Assuming that I am missing something, I went looking for examples of how to get HTML content through a Spring Cloud Gateway application. There are plenty of examples of how to get lists and text from toy microservices, and examples of how to serve static pages from a Spring Cloud Gateway application, but it appears that no one has used Spring Cloud Gateway to access webpages served by other applications! at least, no one has put up an example of doing so.

So if I am missing something that needs to be done, I haven't found it. Or perhaps this is a bug in the Gateway that needs to be reported somewhere?

Can anyone help with this? Does anyone know how to get Spring Cloud Gateway to work correctly with microservices that serve actual web content (static or dynamic)?

0 Answers
Related