diff --git a/build.gradle.kts b/build.gradle.kts index 324ec17..eb1a795 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -29,6 +29,7 @@ dependencies { implementation(libs.ktor.client.core) implementation(libs.ktor.client.cio) implementation(libs.ktor.client.content.negotiation) + implementation(libs.ktor.server.cors) implementation(libs.jackson.dataformat.xml) implementation(libs.ktor.server.config.yaml) testImplementation(libs.ktor.server.test.host) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 6d5796a..814f681 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -15,6 +15,7 @@ ktor-server-config-yaml = { module = "io.ktor:ktor-server-config-yaml", version. ktor-server-test-host = { module = "io.ktor:ktor-server-test-host", version.ref = "ktor-version" } kotlin-test-junit = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlin-version" } ktor-server-status-pages = { module = "io.ktor:ktor-server-status-pages", version.ref = "ktor-version" } +ktor-server-cors = { module = "io.ktor:ktor-server-cors", version.ref = "ktor-version" } ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor-version" } ktor-client-cio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor-version" } ktor-client-content-negotiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktor-version" } diff --git a/src/main/kotlin/Application.kt b/src/main/kotlin/Application.kt index ae2c445..07fe379 100644 --- a/src/main/kotlin/Application.kt +++ b/src/main/kotlin/Application.kt @@ -5,6 +5,7 @@ import io.ktor.server.application.* import io.ktor.server.plugins.* import io.ktor.server.plugins.statuspages.* import io.ktor.server.response.* +import io.ktor.server.plugins.cors.routing.* fun main(args: Array) { io.ktor.server.netty.EngineMain.main(args) @@ -21,5 +22,15 @@ fun Application.module() { } } + install(CORS) { + anyHost() + allowHeader(HttpHeaders.ContentType) + allowHeader(HttpHeaders.Authorization) + allowMethod(HttpMethod.Get) + allowMethod(HttpMethod.Post) + allowMethod(HttpMethod.Put) + allowMethod(HttpMethod.Delete) + } + configureRouting() }