From dbca9ccc662e6c93c764996df3350983f5e7acb3 Mon Sep 17 00:00:00 2001 From: MrPowerGamerBR Date: Thu, 21 Sep 2023 10:33:59 -0300 Subject: [PATCH] Enable CORS (again) --- backend/build.gradle.kts | 1 + .../etherealgambi/backend/EtherealGambi.kt | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/backend/build.gradle.kts b/backend/build.gradle.kts index 4560910..98cd796 100644 --- a/backend/build.gradle.kts +++ b/backend/build.gradle.kts @@ -18,6 +18,7 @@ dependencies { implementation(libs.ktor.server.netty) implementation(libs.ktor.server.compression) implementation(libs.ktor.server.caching.headers) + implementation(libs.ktor.server.cors) implementation(libs.kotlinx.serialization.json) implementation(project(":common")) diff --git a/backend/src/main/kotlin/net/perfectdreams/etherealgambi/backend/EtherealGambi.kt b/backend/src/main/kotlin/net/perfectdreams/etherealgambi/backend/EtherealGambi.kt index 1835a68..c60c0fa 100644 --- a/backend/src/main/kotlin/net/perfectdreams/etherealgambi/backend/EtherealGambi.kt +++ b/backend/src/main/kotlin/net/perfectdreams/etherealgambi/backend/EtherealGambi.kt @@ -7,6 +7,7 @@ import io.ktor.server.engine.* import io.ktor.server.netty.* import io.ktor.server.plugins.cachingheaders.* import io.ktor.server.plugins.compression.* +import io.ktor.server.plugins.cors.routing.* import io.ktor.server.routing.* import kotlinx.coroutines.runBlocking import kotlinx.coroutines.sync.Mutex @@ -100,6 +101,19 @@ class EtherealGambi { } } + // Useful for images in a JavaScript canvas, since by default you CAN'T manipulate external images in a Canvas + install(CORS) { + anyHost() + allowMethod(HttpMethod.Get) + allowMethod(HttpMethod.Post) + allowMethod(HttpMethod.Options) + allowMethod(HttpMethod.Put) + allowMethod(HttpMethod.Patch) + allowMethod(HttpMethod.Delete) + allowHeader(HttpHeaders.AccessControlAllowOrigin) + allowHeader(HttpHeaders.ContentType) + } + routing { for (route in routes) { route.register(this)