Compare commits
2 Commits
225e89df5d
...
203fc9866d
Author | SHA1 | Date | |
---|---|---|---|
203fc9866d | |||
94308202e9 |
18
src/main/java/co/jp/app/config/CorsConfig.java
Normal file
18
src/main/java/co/jp/app/config/CorsConfig.java
Normal file
@ -0,0 +1,18 @@
|
||||
package co.jp.app.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("/api/**") // 允许 /api/ 下的所有请求
|
||||
.allowedOrigins("http://192.168.1.50:5173") // 允许来自该域的请求
|
||||
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") // 允许的 HTTP 方法
|
||||
.allowedHeaders("*") // 允许所有头部
|
||||
.allowCredentials(true); // 允许发送 Cookie
|
||||
}
|
||||
}
|
@ -24,8 +24,6 @@ import co.jp.app.service.UserService;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@CrossOrigin("http://192.168.1.50:5173")
|
||||
@RestController
|
||||
@RequestMapping("/api/user")
|
||||
public class UserController {
|
||||
|
Reference in New Issue
Block a user