White page after successful routing with Spring Cloud Gateway

Viewed 327

Due to a certain lack of support between two technologies I wanted to implement, I find myself in the need to look for a "smarter" proxy server than the current Apache solution I implemented. After some quick digging I found out about Spring Cloud Gateway and Zuul. As I wanted to keep things simple with dependencies, I choose Spring's option.

After some tries in my local environment with an API I had for a different purpose, I managed to get the routing right and a static page when the root is hit. Then I rolled it to my test environment and after dealing with some slightly annoying things I didn't know about Spring Cloud, the proxy worked with another API I have in that environment. I must add, this test were done in curl.

The problem I have now is that the Gateway is supposed to be used to proxy to other, non-boot application deployed in Tomcat. The routing itself works as stated in the title, but nothing is displayed. I double checked the servers were up and access to them properly directly from my browser. Then I tried to hit the test API, also deployed in a Tomcat, with my browser and found that the Get request worked ok but the Post request return 405 error (No error is logged in the prompt).

I've been looking around about this but haven't found anything yet. My initial, uneducated guess was that Spring Cloud Gateway was ment/designed to work with API based applications and/or the front end framework we use is not supported somehow, but I highly doubt that is the case.

As you see, I'm diving into this a bit blindly but the examples I've seen so far aren't particulary deep either, probably because it is fairly simple to understand.

My Java code is nothing but the Bean necesary for the Static content. I moved from Java config to yaml config as this gateway will need to be implemented in two servers with different apps on them. I'll share it anyway for the sake of completeness.

Java code:

@SpringBootApplication
public class GatewayApplication {

    public static void main(String[] args) {
        SpringApplication.run(GatewayApplication.class, args);
    }

    @Bean
    public RouterFunction<ServerResponse> statucResourceLocator(@Value("classpath:/static/index.html") Resource index) {
        return route(GET("/"), request -> ok().contentType(MediaType.TEXT_HTML).bodyValue(index));
    }

}

application.yml

server:
  port: 8080
spring:
  cloud:
    gateway:
      routes:
        # Non-boot app
      - id: app1 
        uri: localhost:8081
        predicates:
        - Path=/app1/**
        # Non-boot app
      - id: app2 <- Non-boot app
        uri: localhost:8082
        predicates:
        - Path=/app2/**
      - id: api
        uri: http://localhost:8000
        predicates:
        - Path=/api/**

Is there something I missed from the Spring tutorial on this? Or is there a certain filter I need to add for other type of content to be displayed? We are using ZK Framework, Java 8 and our Spring version for the current projects is 4.3.8. Yes, we have a bit too much work done to make drastic updates or to change the backend.

Quick update:

I guess this was obvious, but the behaviour is the same if I test this on my local machine with an app that is not an API. I'll try to find the limitations Spring Gateway currently has, as it's still pretty new technology as far as I know.

0 Answers
Related