|
1 | | -/* |
2 | | - * Copyright (c) SKU K-IO-SK |
3 | | - */ |
4 | 1 | package com.sku.aigongmo.global.config; |
5 | 2 |
|
6 | | -import java.util.Arrays; |
7 | 3 | import org.springframework.beans.factory.annotation.Value; |
8 | 4 | import org.springframework.context.annotation.Bean; |
9 | 5 | import org.springframework.context.annotation.Configuration; |
10 | 6 | import org.springframework.web.cors.CorsConfiguration; |
11 | 7 | import org.springframework.web.cors.UrlBasedCorsConfigurationSource; |
12 | 8 |
|
| 9 | +import java.util.Arrays; |
| 10 | + |
13 | 11 | @Configuration |
14 | 12 | public class CorsConfig { |
15 | 13 |
|
16 | | - @Value("${cors.allowed-origins}") |
17 | | - private String[] allowedOrigins; |
| 14 | + @Value("${cors.allowed-origins}") |
| 15 | + private String[] allowedOrigins; |
18 | 16 |
|
19 | | - @Bean |
20 | | - public UrlBasedCorsConfigurationSource corsConfigurationSource() { |
21 | | - CorsConfiguration configuration = new CorsConfiguration(); |
| 17 | + @Bean |
| 18 | + public UrlBasedCorsConfigurationSource corsConfigurationSource() { |
| 19 | + CorsConfiguration configuration = new CorsConfiguration(); |
22 | 20 |
|
23 | | - // 환경 변수에 정의된 출처만 허용 |
24 | | - configuration.setAllowedOrigins(Arrays.asList(allowedOrigins)); |
25 | | - // 리스트에 작성한 HTTP 메소드 요청만 허용 |
26 | | - configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "PATCH")); |
27 | | - // 리스트에 작성한 헤더들이 포함된 요청만 허용 |
28 | | - configuration.setAllowedHeaders(Arrays.asList("Content-Type", "X-Requested-With")); |
29 | | - // 모든 경로에 대해 위의 CORS 설정을 적용 |
30 | | - UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); |
31 | | - source.registerCorsConfiguration("/**", configuration); |
32 | | - return source; |
33 | | - } |
| 21 | + // 환경 변수에 정의된 출처만 허용 |
| 22 | + configuration.setAllowedOrigins(Arrays.asList(allowedOrigins)); |
| 23 | + // 리스트에 작성한 HTTP 메소드 요청만 허용 |
| 24 | + configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "PATCH")); |
| 25 | + // 리스트에 작성한 헤더들이 포함된 요청만 허용 |
| 26 | + configuration.setAllowedHeaders(Arrays.asList("Content-Type", "X-Requested-With")); |
| 27 | + // 모든 경로에 대해 위의 CORS 설정을 적용 |
| 28 | + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); |
| 29 | + source.registerCorsConfiguration("/**", configuration); |
| 30 | + return source; |
| 31 | + } |
34 | 32 | } |
0 commit comments