diff --git a/esua-epdc/epdc-gateway/src/main/java/com/elink/esua/epdc/config/CorsConfig.java b/esua-epdc/epdc-gateway/src/main/java/com/elink/esua/epdc/config/CorsConfig.java index eeba29b0b..5f0515c53 100644 --- a/esua-epdc/epdc-gateway/src/main/java/com/elink/esua/epdc/config/CorsConfig.java +++ b/esua-epdc/epdc-gateway/src/main/java/com/elink/esua/epdc/config/CorsConfig.java @@ -1,13 +1,15 @@ /** * Copyright (c) 2018 人人开源 All rights reserved. - * + *
* https://www.renren.io - * + *
* 版权所有,侵权必究! */ package com.elink.esua.epdc.config; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.web.ServerProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpHeaders; @@ -32,6 +34,9 @@ public class CorsConfig { private static final String MAX_AGE = "18000L"; + @Autowired + private ServerProperties serverProperties; + @Bean public WebFilter corsFilter() { return (ServerWebExchange ctx, WebFilterChain chain) -> { @@ -43,7 +48,7 @@ public class CorsConfig { ServerHttpResponse response = ctx.getResponse(); HttpMethod requestMethod = requestHeaders.getAccessControlRequestMethod(); HttpHeaders headers = response.getHeaders(); - if(!request.getURI().getPath().startsWith("/epdc/ws")) { + if (!request.getURI().getPath().startsWith(serverProperties.getServlet().getContextPath().concat("/ws"))) { headers.add(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, requestHeaders.getOrigin()); headers.add(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true"); }