Fix cors config
This commit is contained in:
4 files changed
+21
-13
No files matched your search
+1
-1
@@ -1,2 +1,2 @@
|
||||
kotlin.code.style=official
|
||||
libVersion=1.0.4
|
||||
libVersion=1.0.5
|
||||
@@ -14,21 +14,14 @@ import org.w3c.fetch.ResponseInit
|
||||
* Auto add cors response headers
|
||||
*/
|
||||
@Suppress("FunctionName")
|
||||
internal fun WorkerApplication._addCorsHeaders(
|
||||
init: ResponseInit,
|
||||
origin: String = "*",
|
||||
allowedMethods: Set<HttpMethod> = setOf(
|
||||
HttpMethod.GET, HttpMethod.POST,
|
||||
HttpMethod.DELETE, HttpMethod.DELETE,
|
||||
HttpMethod.OPTIONS
|
||||
),
|
||||
): ResponseInit {
|
||||
internal fun WorkerApplication._addCorsHeaders(init: ResponseInit, ): ResponseInit {
|
||||
val headers = if (this.corsConfig.enabled) {
|
||||
val corsHeaders = init.headers ?: js("{}")
|
||||
corsHeaders["Access-Control-Allow-Origin"] = origin
|
||||
corsHeaders["Access-Control-Allow-Methods"] = allowedMethods.joinToString(", ")
|
||||
corsHeaders["Access-Control-Allow-Origin"] = corsConfig.origin
|
||||
corsHeaders["Access-Control-Allow-Methods"] = corsConfig.allowedMethods.joinToString(", ")
|
||||
corsHeaders["Access-Control-Allow-Headers"] = "Content-Type, Authorization"
|
||||
corsHeaders["Access-Control-Max-Age"] = "86400"
|
||||
if (corsConfig.allowCredentials) corsHeaders["Access-Control-Allow-Credentials"] = corsConfig.allowCredentials
|
||||
corsHeaders["Access-Control-Max-Age"] = "${corsConfig.maxAge}"
|
||||
corsHeaders
|
||||
} else init.headers
|
||||
return ResponseInit(
|
||||
|
||||
@@ -28,4 +28,8 @@ public class CORSConfig {
|
||||
HttpMethod.DELETE, HttpMethod.DELETE,
|
||||
HttpMethod.OPTIONS
|
||||
)
|
||||
|
||||
public var allowCredentials: Boolean = false
|
||||
|
||||
public var maxAge: Int = 86400
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
||||
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
id("java-gradle-plugin")
|
||||
@@ -19,4 +21,13 @@ gradlePlugin {
|
||||
|
||||
dependencies {
|
||||
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:2.2.21")
|
||||
}
|
||||
|
||||
tasks.compileKotlin {
|
||||
compilerOptions.jvmTarget = JvmTarget.JVM_11
|
||||
}
|
||||
|
||||
tasks.compileJava {
|
||||
sourceCompatibility = "11"
|
||||
targetCompatibility = "11"
|
||||
}
|
||||
Reference in New Issue
Block a user