3 Commits
Author SHA1 Message Date
jaytux 62f952ac68 CORS headers for SSE 2026-08-27 14:29:27 +02:00
jaytux c662626bd8 Server version bump 2026-08-27 14:11:19 +02:00
jaytux e40afb2c3d Server: CORS support on SSE routes 2026-08-27 14:10:04 +02:00
2 changed files with 9 additions and 4 deletions
+1 -1
View File
@@ -7,7 +7,7 @@ plugins {
}
group = "com.jaytux.phoebench"
version = PhoebenchVersion(1, 1, 1)
version = PhoebenchVersion(1, 1, 2)
if((version as PhoebenchVersion) < (rootProject.version as PhoebenchVersion))
throw GradleException("Server version must be at least as high as protocol/common version")
@@ -37,20 +37,23 @@ fun Application.module() {
json()
}
install(SSE) {}
val allowLocalhost = environment.config.propertyOrNull("ktor.cors.enableLocalhostOn")?.getString() ?: "0"
val safeOrigin = environment.config.propertyOrNull("ktor.cors.browserOrigin")?.getString()
install(CORS) {
// -- methods --
allowMethod(HttpMethod.Options)
allowMethod(HttpMethod.Delete)
allowMethod(HttpMethod.Patch)
allowMethod(HttpMethod.Get)
allowMethod(HttpMethod.Post)
// -- headers --
allowHeader(HttpHeaders.Accept)
allowHeader(HttpHeaders.Pragma)
allowHeader(HttpHeaders.Authorization)
allowHeader(HttpHeaders.ContentType)
allowHeader(HttpHeaders.CacheControl)
allowHeader(HttpHeaders.LastEventID)
// -- exposed headers --
exposeHeader(HttpHeaders.ContentType)
allowCredentials = true
allowNonSimpleContentTypes = true
@@ -73,6 +76,8 @@ fun Application.module() {
}
}
install(SSE) {}
install(StatusPages) {
status(HttpStatusCode.Forbidden) { call, status ->
call.respond(status, ErrorResponse("Access Forbidden: CORS failed."))