Skip to content

Commit 986abb4

Browse files
authored
Merge pull request #22 from xebia-functional/21-enable-cors
Enable cors
2 parents 89fcdcc + 605574f commit 986abb4

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ dependencies {
2929
implementation(libs.ktor.client.core)
3030
implementation(libs.ktor.client.cio)
3131
implementation(libs.ktor.client.content.negotiation)
32+
implementation(libs.ktor.server.cors)
3233
implementation(libs.jackson.dataformat.xml)
3334
implementation(libs.ktor.server.config.yaml)
3435
testImplementation(libs.ktor.server.test.host)

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ ktor-server-config-yaml = { module = "io.ktor:ktor-server-config-yaml", version.
1515
ktor-server-test-host = { module = "io.ktor:ktor-server-test-host", version.ref = "ktor-version" }
1616
kotlin-test-junit = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlin-version" }
1717
ktor-server-status-pages = { module = "io.ktor:ktor-server-status-pages", version.ref = "ktor-version" }
18+
ktor-server-cors = { module = "io.ktor:ktor-server-cors", version.ref = "ktor-version" }
1819
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor-version" }
1920
ktor-client-cio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor-version" }
2021
ktor-client-content-negotiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktor-version" }

src/main/kotlin/Application.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import io.ktor.server.application.*
55
import io.ktor.server.plugins.*
66
import io.ktor.server.plugins.statuspages.*
77
import io.ktor.server.response.*
8+
import io.ktor.server.plugins.cors.routing.*
89

910
fun main(args: Array<String>) {
1011
io.ktor.server.netty.EngineMain.main(args)
@@ -21,5 +22,15 @@ fun Application.module() {
2122
}
2223
}
2324

25+
install(CORS) {
26+
anyHost()
27+
allowHeader(HttpHeaders.ContentType)
28+
allowHeader(HttpHeaders.Authorization)
29+
allowMethod(HttpMethod.Get)
30+
allowMethod(HttpMethod.Post)
31+
allowMethod(HttpMethod.Put)
32+
allowMethod(HttpMethod.Delete)
33+
}
34+
2435
configureRouting()
2536
}

0 commit comments

Comments
 (0)