Merge pull request 'watchdog-be: CORSをせっていできるように' (#14) from unos-fe-endpoint into master
Reviewed-on: #14
This commit is contained in:
commit
c472acee43
|
@ -36,6 +36,7 @@ dependencies {
|
||||||
implementation("io.ktor:ktor-server-content-negotiation-jvm")
|
implementation("io.ktor:ktor-server-content-negotiation-jvm")
|
||||||
implementation("io.ktor:ktor-serialization-kotlinx-json-jvm")
|
implementation("io.ktor:ktor-serialization-kotlinx-json-jvm")
|
||||||
implementation("io.ktor:ktor-server-netty-jvm")
|
implementation("io.ktor:ktor-server-netty-jvm")
|
||||||
|
implementation("io.ktor:ktor-server-cors")
|
||||||
implementation("ch.qos.logback:logback-classic:1.5.3")
|
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 com.mongodb.kotlin.client.coroutine.MongoDatabase
|
||||||
import dev.usbharu.unos.watchdog.be.domain.MongoMetricsRepository
|
import dev.usbharu.unos.watchdog.be.domain.MongoMetricsRepository
|
||||||
import io.grpc.ServerBuilder
|
import io.grpc.ServerBuilder
|
||||||
|
import io.ktor.http.*
|
||||||
import io.ktor.serialization.kotlinx.json.*
|
import io.ktor.serialization.kotlinx.json.*
|
||||||
import io.ktor.server.application.*
|
import io.ktor.server.application.*
|
||||||
import io.ktor.server.plugins.contentnegotiation.*
|
import io.ktor.server.plugins.contentnegotiation.*
|
||||||
|
import io.ktor.server.plugins.cors.routing.*
|
||||||
import io.ktor.server.routing.*
|
import io.ktor.server.routing.*
|
||||||
|
import java.net.URI
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
io.ktor.server.netty.EngineMain.main(args)
|
io.ktor.server.netty.EngineMain.main(args)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Application.module() {
|
fun Application.module() {
|
||||||
|
val frontEndUrl = URI(environment.config.property("watchdog.front-url").getString())
|
||||||
install(ContentNegotiation) {
|
install(ContentNegotiation) {
|
||||||
json()
|
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 url = environment.config.property("watchdog.db.url").getString()
|
||||||
val databaseName = environment.config.property("watchdog.db.database").getString()
|
val databaseName = environment.config.property("watchdog.db.database").getString()
|
||||||
|
|
Loading…
Reference in New Issue