watchdog-be: CORSをせっていできるように
This commit is contained in:
parent
a7fe6f988e
commit
1c2044d5e9
|
@ -36,6 +36,7 @@ dependencies {
|
|||
implementation("io.ktor:ktor-server-content-negotiation-jvm")
|
||||
implementation("io.ktor:ktor-serialization-kotlinx-json-jvm")
|
||||
implementation("io.ktor:ktor-server-netty-jvm")
|
||||
implementation("io.ktor:ktor-server-cors")
|
||||
implementation("ch.qos.logback:logback-classic:1.5.3")
|
||||
}
|
||||
|
||||
|
|
|
@ -6,19 +6,33 @@ import com.mongodb.kotlin.client.coroutine.MongoClient
|
|||
import com.mongodb.kotlin.client.coroutine.MongoDatabase
|
||||
import dev.usbharu.unos.watchdog.be.domain.MongoMetricsRepository
|
||||
import io.grpc.ServerBuilder
|
||||
import io.ktor.http.*
|
||||
import io.ktor.serialization.kotlinx.json.*
|
||||
import io.ktor.server.application.*
|
||||
import io.ktor.server.plugins.contentnegotiation.*
|
||||
import io.ktor.server.plugins.cors.routing.*
|
||||
import io.ktor.server.routing.*
|
||||
import java.net.URI
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
io.ktor.server.netty.EngineMain.main(args)
|
||||
}
|
||||
|
||||
fun Application.module() {
|
||||
val frontEndUrl = URI(environment.config.property("watchdog.front-url").getString())
|
||||
install(ContentNegotiation) {
|
||||
json()
|
||||
}
|
||||
install(CORS){
|
||||
allowMethod(HttpMethod.Get)
|
||||
allowMethod(HttpMethod.Post)
|
||||
allowMethod(HttpMethod.Put)
|
||||
allowMethod(HttpMethod.Delete)
|
||||
allowMethod(HttpMethod.Options)
|
||||
allowHost(frontEndUrl.authority, schemes = listOf(frontEndUrl.scheme))
|
||||
allowCredentials = true
|
||||
allowNonSimpleContentTypes = true
|
||||
}
|
||||
|
||||
val url = environment.config.property("watchdog.db.url").getString()
|
||||
val databaseName = environment.config.property("watchdog.db.database").getString()
|
||||
|
|
Loading…
Reference in New Issue