Skip to content

Commit

Permalink
[etc] cors 설정 (#65)
Browse files Browse the repository at this point in the history
Co-authored-by: doji <[email protected]>
  • Loading branch information
k-kbk and dojinyou authored Nov 26, 2023
1 parent 5a1f5b5 commit b86cd5c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
3 changes: 1 addition & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import com.epages.restdocs.apispec.gradle.OpenApi3Task
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jooq.meta.jaxb.Logging
Expand Down Expand Up @@ -130,7 +129,7 @@ tasks.withType<Test> {

tasks.test {
extensions.configure(JacocoTaskExtension::class) {
destinationFile = file("$buildDir/jacoco/jacoco.exec")
setDestinationFile(file("$buildDir/jacoco/jacoco.exec"))
}

finalizedBy(tasks.jacocoTestReport)
Expand Down
30 changes: 30 additions & 0 deletions src/main/kotlin/com/mjucow/eatda/common/config/WebConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +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/**")
.allowedOriginPatterns("*")
.allowedMethods(
HttpMethod.GET.name(),
HttpMethod.POST.name(),
HttpMethod.DELETE.name(),
HttpMethod.PATCH.name(),
HttpMethod.HEAD.name(),
HttpMethod.OPTIONS.name()
)
.allowedHeaders("*")
.allowCredentials(true)
.maxAge(Duration.of(60, ChronoUnit.MINUTES).toSeconds())
}
}

0 comments on commit b86cd5c

Please sign in to comment.