feat(dify): 添加跨域支持

This commit is contained in:
vertoryao 2025-04-24 14:49:49 +08:00
parent ae29fbcba6
commit 44d8353a54

View File

@ -6,6 +6,7 @@ import org.springframework.boot.autoconfigure.web.WebProperties;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.lang.NonNull; import org.springframework.lang.NonNull;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.resource.PathResourceResolver; import org.springframework.web.servlet.resource.PathResourceResolver;
@ -44,4 +45,13 @@ public class WebMvcConfiguration implements WebMvcConfigurer {
return resource; return resource;
} }
} }
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowCredentials(true)
.allowedOrigins("*")
.allowedMethods("*")
.allowedHeaders("*");
}
} }