Seamher | 8ba71e0 | 2025-06-09 22:38:35 +0800 | [diff] [blame^] | 1 | package com.g9.g9backend.config; |
| 2 | |
| 3 | import org.slf4j.Logger; |
| 4 | import org.slf4j.LoggerFactory; |
| 5 | import org.springframework.context.annotation.Configuration; |
| 6 | import org.springframework.web.servlet.config.annotation.CorsRegistry; |
| 7 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
| 8 | |
| 9 | /** |
| 10 | * WebConfig 类用于配置 Spring MVC 的拦截器和 CORS 设置 |
| 11 | * |
| 12 | * @author Seamher |
| 13 | */ |
| 14 | @Configuration |
| 15 | public class WebConfig implements WebMvcConfigurer { |
| 16 | |
| 17 | private static final Logger logger = LoggerFactory.getLogger(WebConfig.class); |
| 18 | |
| 19 | /** |
| 20 | * 配置 CORS 设置 |
| 21 | * |
| 22 | * @param registry CORS 注册表 |
| 23 | */ |
| 24 | @Override |
| 25 | public void addCorsMappings(CorsRegistry registry) { |
| 26 | logger.info("Configuring CORS mappings"); |
| 27 | registry.addMapping("/**") |
| 28 | .allowedOrigins("*") |
| 29 | .allowedMethods("GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS") |
| 30 | .allowedHeaders("*"); |
| 31 | logger.info("CORS mappings configured to allow all origins, methods, and headers"); |
| 32 | } |
| 33 | |
| 34 | } |