There is a simple proxy:
@EnableZuulProxy
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public SimpleFilter simpleFilter(){
return new SimpleFilter();
}
}
Pre filter:
public class SimpleFilter extends ZuulFilter {
private static Logger log = LoggerFactory.getLogger(SimpleFilter.class);
@Override
public String filterType() {
return "pre";
}
@Override
public int filterOrder() {
return 1;
}
@Override
public boolean shouldFilter() {
return true;
}
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
HttpServletRequest request = ctx.getRequest();
log.info(String.format("%s request to %s", request.getMethod(), request.getRequestURL().toString()));
return null;
}
}
and properties:
zuul.ignored-patterns=/myserver/web/**
zuul.routes.myserver.path=/myserver/api/**
zuul.routes.myserver.url=http://localhost:80/myserver/api
zuul.routes.myserver.sensitiveHeaders = Cookie,Set-Cookie
server.port=3000
In general, everything works well.
But the web pages that the proxy sends have links like
href="http://localhost:80/myserver/api/item"
A must be of the form like:
href="http://server_ip:3000/myserver/api/item"
How to configure a server to send the correct links?
Cases:
1.When accessing the myserver directly from the Internet like:
http://server_ip:80/myserver/api/item
server sends the page with the links like:
href="http://server_ip:80/myserver/api/item"
2.When accessing the proxy from the Internet like:
http://server_ip:3000/myserver/api/item
proxy-server sends the page with the links like:
href="http://localhost:80/myserver/api/item"