mkopylec / charon-spring-boot-starter

Reverse proxy implementation in form of a Spring Boot starter.
Apache License 2.0
240 stars 54 forks source link

Mixing static and forwarding endpoints #105

Closed KevinMitchell closed 4 years ago

KevinMitchell commented 4 years ago

Hi,

I'm using Charon with a custom interceptor and it's all working as expected.

  CharonConfigurer charonConfigurer() {
    return charonConfiguration()
        .set(restTemplate().set(timeout().connection(ofMillis(200))
        .add(requestMapping("all requests mapping").set(customInterceptor(interceptor)));
  }

I now want to define some explicit endpoints in my application. Calls to these endpoints should be routed to these endpoints, but everything else should be forwarded as before. So the "all requests mapping" should only be used if nothing else handles it. I've tried various changes to the configuration without success. So could someone suggest the best way of configuring Charon to handle such a case.

Thanks

mkopylec commented 4 years ago

Hi, you need to limit the requests handled by Charon. To do so, you need to set a request path regex that tells Charon which request should be handled. For example, if you configure Charon like below:

    @Bean
    CharonConfigurer charonConfigurer() {
        return charonConfiguration()
                .add(requestMapping("requests handled by Charon").pathRegex("/some/path.*"));
    }

then only requests with path that matches /some/path.* regex pattern will be handled by Charon. Other requests will be handled locally, for example by a Spring @Controller if any is present.

See here for more information.

mkopylec commented 4 years ago

Also, if you want to handle some requests by a filter, you can change the order of Charon's filter:

    @Bean
    CharonConfigurer charonConfigurer() {
        return charonConfiguration()
                .filterOrder(Ordered.LOWEST_PRECEDENCE);
    }

See here for more information.

mkopylec commented 4 years ago

If you still need help, let me know.