2026-09-07 16:54:43 +08:00
|
|
|
package com.moyi.controlplane.config;
|
|
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
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 {
|
|
|
|
|
private final String[] allowedOrigins;
|
|
|
|
|
|
|
|
|
|
public WebConfig(@Value("${moyi.web.cors-origins}") String allowedOrigins) {
|
|
|
|
|
this.allowedOrigins = Arrays.stream(allowedOrigins.split(","))
|
|
|
|
|
.map(String::trim)
|
|
|
|
|
.filter(origin -> !origin.isBlank())
|
|
|
|
|
.toArray(String[]::new);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void addCorsMappings(CorsRegistry registry) {
|
|
|
|
|
registry.addMapping("/**")
|
|
|
|
|
.allowedOrigins(allowedOrigins)
|
|
|
|
|
.allowedMethods("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS")
|
2026-10-13 19:08:50 +08:00
|
|
|
.allowedHeaders("Content-Type", "Authorization", "X-Moyi-Source", "Idempotency-Key", "x-api-key", "anthropic-version", "x-goog-api-key", "X-Moyi-Session")
|
2026-09-20 01:36:22 +08:00
|
|
|
.exposedHeaders("X-Request-Id", "X-Moyi-Cost-CNY")
|
2026-09-07 16:54:43 +08:00
|
|
|
.allowCredentials(true)
|
|
|
|
|
.maxAge(3600);
|
|
|
|
|
}
|
|
|
|
|
}
|