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") .allowedHeaders("Content-Type", "Authorization", "X-Moyi-Source", "Idempotency-Key", "x-api-key", "anthropic-version", "x-goog-api-key", "X-Moyi-Session") .exposedHeaders("X-Request-Id", "X-Moyi-Cost-CNY") .allowCredentials(true) .maxAge(3600); } }