Skip to content

Commit

Permalink
Corsconfig 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
seung-jun2 committed Jun 21, 2024
1 parent f16cfae commit d0a0384
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
35 changes: 35 additions & 0 deletions src/main/java/com/example/healthylife/config/CorsConfig.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@
public interface CommunityService {
//글전체조회
List<CommunityEntity> communityList();

//글등록
CommunityEntity registerCommunity(CommunityEntity communityEntity);
//글 수정
CommunityEntity updateCommunity(CommunityEntity communityEntity);

//글삭제
void deleteBySq(long communitySq);
}

0 comments on commit d0a0384

Please sign in to comment.