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 dbca9cc
Show file tree
Hide file tree
Showing 2 changed files with 15 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

0 comments on commit dbca9cc

Please sign in to comment.