68 lines
2.6 KiB
Kotlin
68 lines
2.6 KiB
Kotlin
package kr.co.vividnext.sodalive.configs
|
|
|
|
import kr.co.vividnext.sodalive.common.CountryInterceptor
|
|
import kr.co.vividnext.sodalive.i18n.LangInterceptor
|
|
import org.springframework.context.annotation.Configuration
|
|
import org.springframework.web.cors.CorsConfiguration
|
|
import org.springframework.web.servlet.config.annotation.CorsRegistry
|
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry
|
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
|
|
|
|
@Configuration
|
|
class WebConfig(
|
|
private val langInterceptor: LangInterceptor,
|
|
private val countryInterceptor: CountryInterceptor
|
|
) : WebMvcConfigurer {
|
|
override fun addInterceptors(registry: InterceptorRegistry) {
|
|
registry.addInterceptor(langInterceptor).addPathPatterns("/**")
|
|
registry.addInterceptor(countryInterceptor).addPathPatterns("/**")
|
|
}
|
|
|
|
override fun addCorsMappings(registry: CorsRegistry) {
|
|
listOf("/admin/member/login", "/member/logout").forEach { path ->
|
|
registry.addMapping(path)
|
|
.allowedOrigins(*AI_CHARACTER_ADMIN_SHARED_AUTH_ALLOWED_ORIGINS.toTypedArray())
|
|
.allowedMethods("*")
|
|
.allowCredentials(true)
|
|
}
|
|
|
|
registry.addMapping("/api/v2/admin/ai-characters/**")
|
|
.allowedOrigins(*AI_CHARACTER_ADMIN_ALLOWED_ORIGINS.toTypedArray())
|
|
.allowedMethods("*")
|
|
.allowCredentials(true)
|
|
|
|
registry.addMapping("/**")
|
|
.allowedOrigins(*ALLOWED_ORIGINS.toTypedArray())
|
|
.allowedMethods("*")
|
|
.allowCredentials(true)
|
|
}
|
|
|
|
companion object {
|
|
private val ALLOWED_ORIGINS = listOf(
|
|
"http://localhost:8888",
|
|
"https://creator.sodalive.net",
|
|
"https://test-creator.sodalive.net",
|
|
"https://test-admin.sodalive.net",
|
|
"https://admin.sodalive.net"
|
|
)
|
|
|
|
private val AI_CHARACTER_ADMIN_ALLOWED_ORIGINS = listOf(
|
|
"http://localhost:8888",
|
|
"https://test-character-admin.sodalive.net",
|
|
"https://character-admin.sodalive.net"
|
|
)
|
|
|
|
private val AI_CHARACTER_ADMIN_SHARED_AUTH_ALLOWED_ORIGINS =
|
|
(ALLOWED_ORIGINS + AI_CHARACTER_ADMIN_ALLOWED_ORIGINS).distinct()
|
|
|
|
internal fun createAiCharacterAdminCorsConfiguration(): CorsConfiguration {
|
|
return CorsConfiguration().apply {
|
|
applyPermitDefaultValues()
|
|
allowedOrigins = AI_CHARACTER_ADMIN_ALLOWED_ORIGINS
|
|
allowedMethods = listOf(CorsConfiguration.ALL)
|
|
allowCredentials = true
|
|
}
|
|
}
|
|
}
|
|
}
|