WebConfig.java 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. package com.njuzr.eaibackend.config;
  2. import org.springframework.context.annotation.Configuration;
  3. import org.springframework.web.servlet.config.annotation.CorsRegistry;
  4. import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
  5. /**
  6. * @author: Leonezhurui
  7. * @Date: 2024/2/19 - 11:44
  8. * @Package: EAI-Backend
  9. */
  10. @Configuration
  11. public class WebConfig implements WebMvcConfigurer {
  12. //设置允许访问的来源
  13. String[] origins = new String[]{
  14. "http://localhost:3000",
  15. "http://localhost:3001",
  16. "http://127.0.0.1:4000",
  17. "http://127.0.0.1:4001",
  18. "http://139.196.252.184",
  19. "http://139.196.252.184:8071",
  20. "http://air.seec.seecoder.cn",
  21. "https://air.seec.seecoder.cn"
  22. };
  23. @Override
  24. public void addCorsMappings(CorsRegistry registry) {
  25. registry.addMapping("/**") // 对所有路径应用规则
  26. .allowedOriginPatterns("*")
  27. .allowedMethods("GET", "POST", "PUT", "DELETE") // 允许的请求方法
  28. .allowedHeaders("*") // 允许的请求头
  29. .allowCredentials(true) // 允许发送Cookies
  30. .maxAge(3600); // 预检请求的缓存时间(秒)
  31. }
  32. }