Skip to content

Commit 0c1e03e

Browse files
authored
Merge pull request #64 from dnd-side-project/dev
CORS ์„ค์ •
2 parents 4735a49 + d8ad5cc commit 0c1e03e

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.example.demo.global.cors;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.web.cors.CorsConfiguration;
6+
import org.springframework.web.cors.reactive.CorsWebFilter;
7+
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
8+
9+
import java.util.List;
10+
11+
@Configuration
12+
public class WebFluxCorsConfig {
13+
14+
@Bean
15+
public CorsWebFilter corsWebFilter() {
16+
CorsConfiguration config = new CorsConfiguration();
17+
// ์ž๊ฒฉ์ฆ๋ช…(์ฟ ํ‚ค/Authorization) ํ—ˆ์šฉ ์‹œ ์˜ค๋ฆฌ์ง„์€ ๋ฐ˜๋“œ์‹œ ๊ตฌ์ฒด์ ์œผ๋กœ ๋‚˜์—ด
18+
config.setAllowCredentials(true);
19+
config.setAllowedOrigins(List.of(
20+
"http://localhost:5173",
21+
"https://deulak-dev.vercel.app",
22+
"https://deulak.com"
23+
));
24+
config.setAllowedMethods(List.of("GET","POST","PUT","PATCH","DELETE","OPTIONS"));
25+
config.setAllowedHeaders(List.of("*"));
26+
config.setExposedHeaders(List.of("Authorization","Location"));
27+
config.setMaxAge(3600L);
28+
29+
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
30+
source.registerCorsConfiguration("/**", config);
31+
return new CorsWebFilter(source);
32+
}
33+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.example.demo.global.cors;
2+
3+
import org.springframework.context.annotation.Configuration;
4+
import org.springframework.web.servlet.config.annotation.CorsRegistry;
5+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
6+
7+
@Configuration
8+
public class WebMvcCorsConfig implements WebMvcConfigurer {
9+
10+
@Override
11+
public void addCorsMappings(CorsRegistry registry) {
12+
registry.addMapping("/**") // ๋ชจ๋“  ์—”๋“œํฌ์ธํŠธ์— CORS ์ ์šฉ
13+
.allowedOrigins(
14+
"http://localhost:5173",
15+
"https://deulak-dev.vercel.app",
16+
"https://deulak.com"
17+
)
18+
.allowedMethods("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS")
19+
.allowedHeaders("*")
20+
.exposedHeaders("Authorization", "Location")
21+
.allowCredentials(true)
22+
.maxAge(3600); // preflight ๊ฒฐ๊ณผ ์บ์‹ฑ (์ดˆ ๋‹จ์œ„)
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.example.demo.global.cors;
2+
3+
import org.springframework.context.annotation.Configuration;
4+
import org.springframework.web.servlet.config.annotation.CorsRegistry;
5+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
6+
7+
@Configuration
8+
public class WebMvcCorsConfig implements WebMvcConfigurer {
9+
10+
@Override
11+
public void addCorsMappings(CorsRegistry registry) {
12+
registry.addMapping("/**") // ๋ชจ๋“  ์—”๋“œํฌ์ธํŠธ์— CORS ์ ์šฉ
13+
.allowedOrigins(
14+
"http://localhost:5173",
15+
"https://deulak-dev.vercel.app",
16+
"https://deulak.com"
17+
)
18+
.allowedMethods("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS")
19+
.allowedHeaders("*")
20+
.exposedHeaders("Authorization", "Location")
21+
.allowCredentials(true)
22+
.maxAge(3600); // preflight ๊ฒฐ๊ณผ ์บ์‹ฑ (์ดˆ ๋‹จ์œ„)
23+
}
24+
}

0 commit comments

Comments
ย (0)