Skip to content

Commit

Permalink
fix origin patterns and refactor readable
Browse files Browse the repository at this point in the history
  • Loading branch information
dojinyou committed Nov 26, 2023
1 parent 6b6d7f1 commit eb889d0
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/main/kotlin/com/mjucow/eatda/common/config/WebConfig.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
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
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())
}
}

0 comments on commit eb889d0

Please sign in to comment.