Skip to content

Commit

Permalink
[Fix] Cors 에러
Browse files Browse the repository at this point in the history
  • Loading branch information
jiyunio committed Nov 14, 2024
1 parent fd71892 commit 49c6bd9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/main/java/com/basic/study/config/SecurityConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.basic.study.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
Expand All @@ -13,6 +14,8 @@

@Configuration
public class SecurityConfig {
@Value("${web.port}")
private String port;

@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
Expand All @@ -28,8 +31,9 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
@Bean
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(List.of("*"));
configuration.setAllowedOrigins(List.of("http://localhost:" + port));
configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE"));
configuration.setAllowCredentials(true);
configuration.setMaxAge(3600L);

UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
Expand Down

0 comments on commit 49c6bd9

Please sign in to comment.