7

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"

1 Answer 1

3

Understood and tried different options.
All I needed to solve the problem was add to the settings:
.properties

......
zuul.add-host-header = true 
......

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.