From d0a0384008e88e81835d7e4e9464e8318ffecb9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=8A=B9=EC=A4=80?= Date: Fri, 21 Jun 2024 17:24:40 +0900 Subject: [PATCH] =?UTF-8?q?Corsconfig=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../healthylife/config/CorsConfig.java | 35 +++++++++++++++++++ .../healthylife/service/CommunityService.java | 2 -- 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/example/healthylife/config/CorsConfig.java diff --git a/src/main/java/com/example/healthylife/config/CorsConfig.java b/src/main/java/com/example/healthylife/config/CorsConfig.java new file mode 100644 index 0000000..2385c7b --- /dev/null +++ b/src/main/java/com/example/healthylife/config/CorsConfig.java @@ -0,0 +1,35 @@ +package com.example.healthylife.config; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +@Configuration +public class CorsConfig { + + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + CorsConfiguration config = new CorsConfiguration(); + + // 허용할 Origin 설정 + config.addAllowedOrigin("http://ec2-43-201-150-178.ap-northeast-2.compute.amazonaws.com:8081/"); + config.addAllowedOrigin("http://localhost:8081/swagger-ui/index.html"); + + // 모든 HTTP 메서드 허용 + config.addAllowedMethod("*"); + + // 모든 헤더 허용 + config.addAllowedHeader("*"); + + // 자격 증명 허용 + config.setAllowCredentials(true); + + // 모든 경로에 대해 위의 CORS 설정 적용 + source.registerCorsConfiguration("/**", config); + + // CORS 필터 반환 + return new CorsFilter(source); + } +} diff --git a/src/main/java/com/example/healthylife/service/CommunityService.java b/src/main/java/com/example/healthylife/service/CommunityService.java index f4735fd..334fb87 100644 --- a/src/main/java/com/example/healthylife/service/CommunityService.java +++ b/src/main/java/com/example/healthylife/service/CommunityService.java @@ -10,12 +10,10 @@ public interface CommunityService { //글전체조회 List communityList(); - //글등록 CommunityEntity registerCommunity(CommunityEntity communityEntity); //글 수정 CommunityEntity updateCommunity(CommunityEntity communityEntity); - //글삭제 void deleteBySq(long communitySq); }