|
@ -1,13 +1,15 @@ |
|
|
/** |
|
|
/** |
|
|
* Copyright (c) 2018 人人开源 All rights reserved. |
|
|
* Copyright (c) 2018 人人开源 All rights reserved. |
|
|
* |
|
|
* <p> |
|
|
* https://www.renren.io
|
|
|
* https://www.renren.io
|
|
|
* |
|
|
* <p> |
|
|
* 版权所有,侵权必究! |
|
|
* 版权所有,侵权必究! |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
package com.elink.esua.epdc.config; |
|
|
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.Bean; |
|
|
import org.springframework.context.annotation.Configuration; |
|
|
import org.springframework.context.annotation.Configuration; |
|
|
import org.springframework.http.HttpHeaders; |
|
|
import org.springframework.http.HttpHeaders; |
|
@ -32,6 +34,9 @@ public class CorsConfig { |
|
|
|
|
|
|
|
|
private static final String MAX_AGE = "18000L"; |
|
|
private static final String MAX_AGE = "18000L"; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private ServerProperties serverProperties; |
|
|
|
|
|
|
|
|
@Bean |
|
|
@Bean |
|
|
public WebFilter corsFilter() { |
|
|
public WebFilter corsFilter() { |
|
|
return (ServerWebExchange ctx, WebFilterChain chain) -> { |
|
|
return (ServerWebExchange ctx, WebFilterChain chain) -> { |
|
@ -43,7 +48,7 @@ public class CorsConfig { |
|
|
ServerHttpResponse response = ctx.getResponse(); |
|
|
ServerHttpResponse response = ctx.getResponse(); |
|
|
HttpMethod requestMethod = requestHeaders.getAccessControlRequestMethod(); |
|
|
HttpMethod requestMethod = requestHeaders.getAccessControlRequestMethod(); |
|
|
HttpHeaders headers = response.getHeaders(); |
|
|
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_ORIGIN, requestHeaders.getOrigin()); |
|
|
headers.add(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true"); |
|
|
headers.add(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true"); |
|
|
} |
|
|
} |
|
|