From 2ff54270fe6525c2de7d57861dafb3c764e73dd8 Mon Sep 17 00:00:00 2001 From: rongchao Date: Tue, 29 Oct 2019 17:14:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8gateway=E8=B7=A8=E5=9F=9F=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E4=B8=AD=E8=BF=87=E6=BB=A4=E6=8E=89websocket=E6=A8=A1?= =?UTF-8?q?=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/elink/esua/epdc/config/CorsConfig.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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"); }