🔄Update: 配置了跨域
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package cn.hezhaohui.mail.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class WebConfig implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**") // 应用到所有路径
|
||||
.allowedOrigins("http://localhost:5173") // 允许前端开发服务器的源
|
||||
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") // 允许的HTTP方法
|
||||
.allowedHeaders("*") // 允许所有header
|
||||
.allowCredentials(true) // 允许发送凭证信息(如cookies)
|
||||
.maxAge(3600); // 预检请求的有效期,单位为秒
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user