From bab0e0198c2482b34de5bf5009d924a32514f995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=84=B8=EC=A7=84?= Date: Sun, 7 Jan 2024 19:55:33 +0900 Subject: [PATCH] =?UTF-8?q?[HOTFIX]:=20CORS=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/config/security/WebMvcConfig.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/main/java/com/finfellows/global/config/security/WebMvcConfig.java diff --git a/src/main/java/com/finfellows/global/config/security/WebMvcConfig.java b/src/main/java/com/finfellows/global/config/security/WebMvcConfig.java new file mode 100644 index 0000000..29940fb --- /dev/null +++ b/src/main/java/com/finfellows/global/config/security/WebMvcConfig.java @@ -0,0 +1,26 @@ +package com.finfellows.global.config.security; + +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; + +@Configuration +public class WebMvcConfig implements WebMvcConfigurer{ + + private final long MAX_AGE_SECS = 3600; + + @Value("${app.cors.allowed-origins}") + private String[] allowedOrigins; + + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**") + .allowedOrigins(allowedOrigins) + .allowedMethods("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS") + .allowedHeaders("*") + .allowCredentials(true) + .maxAge(MAX_AGE_SECS); + } + +}