Skip to content

Commit

Permalink
Enable CORS (again)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrPowerGamerBR committed Sep 21, 2023
1 parent b58a5b9 commit 7a94e36
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions backend/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

0 comments on commit 7a94e36

Please sign in to comment.