From eb889d0fc5b60a746f63f43593c247ad9a9276bc Mon Sep 17 00:00:00 2001 From: doji Date: Sun, 26 Nov 2023 17:28:39 +0900 Subject: [PATCH] fix origin patterns and refactor readable --- .../com/mjucow/eatda/common/config/WebConfig.kt | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/mjucow/eatda/common/config/WebConfig.kt b/src/main/kotlin/com/mjucow/eatda/common/config/WebConfig.kt index c3d9fd4..f22f016 100644 --- a/src/main/kotlin/com/mjucow/eatda/common/config/WebConfig.kt +++ b/src/main/kotlin/com/mjucow/eatda/common/config/WebConfig.kt @@ -1,9 +1,12 @@ package com.mjucow.eatda.common.config import org.springframework.context.annotation.Configuration +import org.springframework.http.HttpMethod import org.springframework.web.servlet.config.annotation.CorsRegistry import org.springframework.web.servlet.config.annotation.EnableWebMvc import org.springframework.web.servlet.config.annotation.WebMvcConfigurer +import java.time.Duration +import java.time.temporal.ChronoUnit @Configuration @EnableWebMvc @@ -11,10 +14,17 @@ class WebConfig : WebMvcConfigurer { override fun addCorsMappings(registry: CorsRegistry) { registry.addMapping("/api/**") - .allowedOrigins("*") - .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") + .allowedOriginPatterns("*") + .allowedMethods( + HttpMethod.GET.name(), + HttpMethod.POST.name(), + HttpMethod.DELETE.name(), + HttpMethod.PATCH.name(), + HttpMethod.HEAD.name(), + HttpMethod.OPTIONS.name(), + ) .allowedHeaders("*") .allowCredentials(true) - .maxAge(3600) + .maxAge(Duration.of(60, ChronoUnit.MINUTES).toSeconds()) } }