JSESSIONID 다른 도메인에 전달

2025. 3. 14. 18:01Java/Spring Boot

client

credentials: 'include'

        const response = await fetch('http://localhost:8080/topics/' + name, { // REST Proxy endpoint
            method: 'POST',
            headers: {
                'Content-Type': 'application/vnd.kafka.avro.v2+json'
            },
            credentials: 'include', // ✅ This line allows cookies like JSESSIONID to be sent
            body: JSON.stringify(payload)
        });

server(데이터를 받는 곳)

.allowCredentials(true);

@Configuration
public class CorsConfig {
    @Bean
    public WebMvcConfigurer corsConfigurer() {
        return new WebMvcConfigurer() {
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                registry.addMapping("/**")
                        .allowedOrigins("도메인1", "도메인2") // Match your HTML server address
                        .allowedMethods("*")
                        .allowedHeaders("*")
                        .allowCredentials(true); 
            }
        };
    }
}