Simplify CORS handling

This makes caching simpler to reason about (no Vary header) and more
efficient (also because there is no Vary header).

Signed-off-by: Graham <gpe@openrs2.org>
Graham 2 years ago
parent ddfc472c84
commit 33ecd68654
  1. 12
      archive/src/main/kotlin/org/openrs2/archive/web/WebServer.kt
  2. 2
      gradle/libs.versions.toml

@ -2,7 +2,9 @@ package org.openrs2.archive.web
import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.databind.ObjectMapper
import io.ktor.http.ContentType import io.ktor.http.ContentType
import io.ktor.http.HttpHeaders
import io.ktor.serialization.jackson.JacksonConverter import io.ktor.serialization.jackson.JacksonConverter
import io.ktor.server.application.*
import io.ktor.server.application.ApplicationCall import io.ktor.server.application.ApplicationCall
import io.ktor.server.application.call import io.ktor.server.application.call
import io.ktor.server.application.install import io.ktor.server.application.install
@ -14,9 +16,9 @@ import io.ktor.server.plugins.autohead.AutoHeadResponse
import io.ktor.server.plugins.cachingheaders.CachingHeaders import io.ktor.server.plugins.cachingheaders.CachingHeaders
import io.ktor.server.plugins.conditionalheaders.ConditionalHeaders import io.ktor.server.plugins.conditionalheaders.ConditionalHeaders
import io.ktor.server.plugins.contentnegotiation.ContentNegotiation import io.ktor.server.plugins.contentnegotiation.ContentNegotiation
import io.ktor.server.plugins.cors.routing.CORS
import io.ktor.server.plugins.defaultheaders.DefaultHeaders import io.ktor.server.plugins.defaultheaders.DefaultHeaders
import io.ktor.server.plugins.forwardedheaders.XForwardedHeaders import io.ktor.server.plugins.forwardedheaders.XForwardedHeaders
import io.ktor.server.response.header
import io.ktor.server.response.respond import io.ktor.server.response.respond
import io.ktor.server.response.respondRedirect import io.ktor.server.response.respondRedirect
import io.ktor.server.routing.get import io.ktor.server.routing.get
@ -44,9 +46,11 @@ public class WebServer @Inject constructor(
install(CachingHeaders) install(CachingHeaders)
install(ConditionalHeaders) install(ConditionalHeaders)
install(CORS) { install(createApplicationPlugin(name = "CORS") {
anyHost() onCall { call ->
} call.response.header(HttpHeaders.AccessControlAllowOrigin, "*")
}
})
install(ContentNegotiation) { install(ContentNegotiation) {
ignoreType<ThymeleafContent>() ignoreType<ThymeleafContent>()

@ -62,7 +62,6 @@ ktor-server-autoHeadResponse = { module = "io.ktor:ktor-server-auto-head-respons
ktor-server-cachingHeaders = { module = "io.ktor:ktor-server-caching-headers", version.ref = "ktor" } ktor-server-cachingHeaders = { module = "io.ktor:ktor-server-caching-headers", version.ref = "ktor" }
ktor-server-conditionalHeaders = { module = "io.ktor:ktor-server-conditional-headers", version.ref = "ktor" } ktor-server-conditionalHeaders = { module = "io.ktor:ktor-server-conditional-headers", version.ref = "ktor" }
ktor-server-contentNegotiation = { module = "io.ktor:ktor-server-content-negotiation", version.ref = "ktor" } ktor-server-contentNegotiation = { module = "io.ktor:ktor-server-content-negotiation", version.ref = "ktor" }
ktor-server-cors = { module = "io.ktor:ktor-server-cors", version.ref = "ktor" }
ktor-server-defaultHeaders = { module = "io.ktor:ktor-server-default-headers", version.ref = "ktor" } ktor-server-defaultHeaders = { module = "io.ktor:ktor-server-default-headers", version.ref = "ktor" }
ktor-server-forwardedHeader = { module = "io.ktor:ktor-server-forwarded-header", version.ref = "ktor" } ktor-server-forwardedHeader = { module = "io.ktor:ktor-server-forwarded-header", version.ref = "ktor" }
ktor-server-jetty = { module = "io.ktor:ktor-server-jetty", version.ref = "ktor" } ktor-server-jetty = { module = "io.ktor:ktor-server-jetty", version.ref = "ktor" }
@ -95,7 +94,6 @@ ktor = [
"ktor-server-cachingHeaders", "ktor-server-cachingHeaders",
"ktor-server-conditionalHeaders", "ktor-server-conditionalHeaders",
"ktor-server-contentNegotiation", "ktor-server-contentNegotiation",
"ktor-server-cors",
"ktor-server-defaultHeaders", "ktor-server-defaultHeaders",
"ktor-server-forwardedHeader", "ktor-server-forwardedHeader",
"ktor-server-jetty", "ktor-server-jetty",

Loading…
Cancel
Save