tag(修复):修复跨域错误
This commit is contained in:
@@ -34,14 +34,17 @@ fun Application.configureRouting() {
|
||||
}
|
||||
}
|
||||
install(CORS) {
|
||||
val configuredOrigins = this@configureRouting.environment.config
|
||||
.propertyOrNull("cors.allowedOrigins")
|
||||
?.getString()
|
||||
?.split(",")
|
||||
val configuredOrigins = (
|
||||
this@configureRouting.environment.config.propertyOrNull("cors.allowedOrigins")
|
||||
?.getString()
|
||||
?: System.getenv("CORS_ALLOWED_ORIGINS")
|
||||
?: "http://localhost:5173"
|
||||
)
|
||||
.split(",")
|
||||
?.map(String::trim)
|
||||
?.filter(String::isNotEmpty)
|
||||
.orEmpty()
|
||||
configuredOrigins.ifEmpty { listOf("http://localhost:5173") }.forEach { origin ->
|
||||
configuredOrigins.forEach { origin ->
|
||||
allowHost(
|
||||
host = origin.removePrefix("http://").removePrefix("https://"),
|
||||
schemes = listOf(if (origin.startsWith("https://")) "https" else "http"),
|
||||
|
||||
@@ -3,7 +3,6 @@ package top.OrangeRoll
|
||||
import io.ktor.client.request.get
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.server.testing.testApplication
|
||||
import configureRouting
|
||||
import kotlin.test.*
|
||||
|
||||
class ServerTest {
|
||||
|
||||
Reference in New Issue
Block a user