mirror of
https://github.com/ClovertaTheTrilobita/SanYeCao-WebAPi.git
synced 2026-04-01 15:04:52 +00:00
feature: 允许跨源调用
This commit is contained in:
parent
b2960541ba
commit
ae1c7b06f7
1 changed files with 17 additions and 0 deletions
17
src/main/java/com/cloverta/webapi/config/CorsConfig.java
Normal file
17
src/main/java/com/cloverta/webapi/config/CorsConfig.java
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
package com.cloverta.webapi.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 CorsConfig implements WebMvcConfigurer {
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**") // 应用于所有端点
|
||||
.allowedOrigins("*") // 允许所有来源
|
||||
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") // 允许的方法
|
||||
.allowedHeaders("*") // 允许所有头部
|
||||
.maxAge(3600); // 预检请求缓存时间(秒)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue