feat: 跨域允许配置多条IP

This commit is contained in:
BenjaminNH 2025-08-05 12:56:04 +08:00
parent 086c5f3f31
commit 99281f8166
2 changed files with 3 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import java.util.Arrays;
import java.util.List;
@Configuration
@ -18,7 +19,7 @@ public class CorsConfig {
@Bean
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration config = new CorsConfiguration();
config.setAllowedOriginPatterns(List.of(allowedOrigins));
config.setAllowedOriginPatterns(Arrays.asList(allowedOrigins.split(",")));
config.setAllowCredentials(true);
config.addAllowedHeader("*");
config.addAllowedMethod("*");

View File

@ -16,7 +16,7 @@ jwt:
secret: your-secret
equip-reserve:
device-days: 7
allowed-origins: http://localhost:5173
allowed-origins: "http://localhost:5173,http://127.0.0.1:5173"
mybatis-plus:
mapper-locations: classpath:mapper/*.xml
configuration: