Commit 914a09b3 authored by zengtianlai3's avatar zengtianlai3

修改CORS跨域资源共享

parent dce5bfa8
...@@ -3,6 +3,7 @@ package iot.sixiang.license.config; ...@@ -3,6 +3,7 @@ package iot.sixiang.license.config;
import iot.sixiang.license.jwt.AuthenticationInterceptor; import iot.sixiang.license.jwt.AuthenticationInterceptor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*; import org.springframework.web.servlet.config.annotation.*;
...@@ -14,11 +15,17 @@ public class CorsConfig implements WebMvcConfigurer { ...@@ -14,11 +15,17 @@ public class CorsConfig implements WebMvcConfigurer {
@Autowired @Autowired
AuthenticationInterceptor authenticationInterceptor; AuthenticationInterceptor authenticationInterceptor;
@Value("${cros.cros_allowed_origins}")
private String[] allowedOrigins;
@Value("${cros.cros_allowed_method}")
private String[] allowedMethods;
@Override @Override
public void addCorsMappings(CorsRegistry registry) { public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**") registry.addMapping("/**")
.allowedOrigins("*") .allowedOrigins(allowedOrigins)
.allowedMethods("*") .allowedMethods(allowedMethods)
.allowCredentials(true) .allowCredentials(true)
.maxAge(3600) .maxAge(3600)
.allowedHeaders("*"); .allowedHeaders("*");
......
...@@ -12,3 +12,7 @@ logging: ...@@ -12,3 +12,7 @@ logging:
server: server:
tomcat: tomcat:
port-header: HEAD,PUT,DELETE,OPTIONS,TRACE,COPY,SEARCH,PROPFIND port-header: HEAD,PUT,DELETE,OPTIONS,TRACE,COPY,SEARCH,PROPFIND
cros:
cros_allowed_origins: http://192.168.1.88:8080, http://localhost:8868
cros_allowed_method: GET,POST
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment