Context Path with Webflux

后端 未结 9 1178
借酒劲吻你
借酒劲吻你 2021-02-07 18:52

I\'ve been trying to find a way to set the context path for a webflux application. I know I can configure it using

server.servlet.context-path

9条回答
  •  再見小時候
    2021-02-07 19:36

    You can use web filter to make WebFlux support contextPath

    @Bean
    public WebFilter contextPathWebFilter() {
        String contextPath = serverProperties.getServlet().getContextPath();
        return (exchange, chain) -> {
            ServerHttpRequest request = exchange.getRequest();
            if (request.getURI().getPath().startsWith(contextPath)) {
                return chain.filter(
                    exchange.mutate()
                    .request(request.mutate().contextPath(contextPath).build())
                    .build());
            }
            return chain.filter(exchange);
        };
    }
    

提交回复
热议问题