Skip to content

Commit

Permalink
feat: CORS ์„ค์ • (#90)
Browse files Browse the repository at this point in the history
* feat: CORS ์„ค์ •

* refactor: CORS ์„ค์ • ๋ถ„๋ฆฌ

* test: yml์— CORS ์„ค์ • ์ถ”๊ฐ€

* feat: Origin ์ถ”๊ฐ€

* feat: Cors ์„ค์ •์— HTTP OPTIONS ๋ฉ”์„œ๋“œ ์ถ”๊ฐ€

---------

Co-authored-by: juha <[email protected]>
  • Loading branch information
Arachneee and khabh authored Jul 24, 2024
1 parent fc4138c commit 20519e7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
27 changes: 27 additions & 0 deletions server/src/main/java/server/haengdong/config/WebConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package server.haengdong.config;

import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@RequiredArgsConstructor
@Configuration
public class WebConfig implements WebMvcConfigurer {

@Value("${cors.max-age}")
private Long maxAge;

@Value("${cors.allowed-origins}")
private String[] allowedOrigins;

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins(allowedOrigins)
.allowedMethods("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS")
.allowedHeaders("*")
.maxAge(maxAge);
}
}
4 changes: 4 additions & 0 deletions server/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ spring:
format_sql: true
show-sql: true

cors:
max-age: 3600
allowed-origins: http://localhost:3000, https://haengdong.pro, https://dev.haengdong.pro, https://app.haengdong.pro

---

spring:
Expand Down
3 changes: 3 additions & 0 deletions server/src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ spring:
format_sql: true
hibernate:
ddl-auto: create-drop
cors:
max-age: 3600
allowed-origins: http://localhost:8080

0 comments on commit 20519e7

Please sign in to comment.