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) diff --git a/settings.gradle.kts b/settings.gradle.kts index 83a19d4..3ba2667 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -23,6 +23,7 @@ dependencyResolutionManagement { library("ktor-server-netty", "io.ktor", "ktor-server-netty").versionRef(ktor) library("ktor-server-compression", "io.ktor", "ktor-server-compression").versionRef(ktor) library("ktor-server-caching-headers", "io.ktor", "ktor-server-caching-headers").versionRef(ktor) + library("ktor-server-cors", "io.ktor", "ktor-server-cors").versionRef(ktor) } } } \ No newline at end of file