Simple reverse proxy
Easily set up a simple proxy reverse using Spring Boot without tape, Eureka or Hystrix.
Just comment on your main application class with @EnableZuulProxyand set the following property in your configuration:
ribbon.eureka.enabled=false
Then define your routes in your configuration as follows:
zuul.routes.<route_name>.path=<route_path>
zuul.routes.<route_name>.url=http://<url_to_host>/
where <route_name>is the arbitrary name for your route, and <route_path>is the path using the Ant path match.
So a concrete example would be something like this
zuul.routes.userservice.path=users/**
zuul.routes.userservice.url=http://localhost:9999/
Custom filters
You can also implement your own authentication and any additional headers by expanding and implementing the class ZuulFilterand adding it as @Beanto your class @Configuration.
So, another specific example:
public class MyFilter extends ZuulFilter {
@Override
public String filterType() {
return "pre";
}
@Override
public int filterOrder() {
return 0;
}
@Override
public boolean shouldFilter() {
return true;
}
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
HttpServletRequest request = ctx.getRequest();
ctx.addZuulRequestHeader("x-custom-header", "foobar");
return null;
}
}
and then
@Configuration
public class GatewayApplication {
@Bean
public MyFilter myFilter() {
return new myFilter();
}
}