Skip to content

Commit

Permalink
feat(#25): Add cors configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
goalSetter09 committed Jan 12, 2025
1 parent 2d123eb commit 807f9b7
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/main/java/com/cotato/kampus/global/config/CorsConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.cotato.kampus.global.config;

import java.util.List;

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 {

private static final String[] ORIGINS = {
"http://localhost:3000",
"http://54.180.123.60:8080",
"https://kampus.kro.kr"
};

private static final String[] ALLOWED_HEADERS = {
"Authorization",
"Refresh-Token"
};

@Bean
public CorsFilter corsFilter() {
CorsConfiguration config = new CorsConfiguration();

config.setAllowCredentials(true);
config.setAllowedOrigins(List.of(ORIGINS));
config.addAllowedHeader("*");
config.addAllowedMethod("*");
config.setExposedHeaders(List.of(ALLOWED_HEADERS));
config.setMaxAge(3600L);

UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", config);

return new CorsFilter(source);
}
}

0 comments on commit 807f9b7

Please sign in to comment.