Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REFACTOR] CORS 설정 변경 #226

Merged
merged 2 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.whoz_in.main_api.config.security;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
Expand Down Expand Up @@ -50,9 +53,13 @@ public PasswordEncoder passwordEncoder() {

//security에서 사용할 Cors 설정을 정의합니다
@Bean
public CorsConfigurationSource corsConfigurationSource(@Value("${frontend.base-url}") String frontendBaseUrl) {
public CorsConfigurationSource corsConfigurationSource(
@Value("${frontend.main.base-url}") String mainBaseUrl,
@Value("${frontend.network-api.base-urls}") List<String> networkBaseUrls) {
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.setAllowedOrigins(List.of(frontendBaseUrl)); //TODO: 내부 아이피 추가
Set<String> corsUrls = new HashSet<>(networkBaseUrls);
corsUrls.add(mainBaseUrl);
corsConfiguration.setAllowedOrigins(List.copyOf(corsUrls));
corsConfiguration.setAllowedMethods(List.of("*"));
corsConfiguration.setAllowedHeaders(List.of("*"));
corsConfiguration.setAllowCredentials(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
@RequiredArgsConstructor
public class LoginSuccessHandler extends SimpleUrlAuthenticationSuccessHandler {
private static final String ENDPOINT = "/oauth/success";
@Value("${frontend.base-url}")
@Value("${frontend.main.base-url}")
private String frontendBaseUrl;
private final CookieFactory cookieFactory;
private final UriBuilderFactory uriBuilderFactory;
Expand Down
5 changes: 4 additions & 1 deletion modules/main-api/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ server:
port: 2470 # 24시간 운영 + main-api니까 0번째

frontend:
base-url: ${FRONTEND_URL}
main: # 메인 프론트 서버
base-url: ${FRONTEND.MAIN.BASE-URL} # 배열이면 안됨
network-api: # 네트워크 api에 띄워진 서버 (기기 등록을 위한)
base-urls: ${FRONTEND.NETWORK-API.BASE-URLS} # 배열 가능 (network-api가 여러 개일 수 있으므로)

api-key: ${API_KEY}

Expand Down