feat: allow cross-origin API requests for the web client
The Kotlin/Wasm client can be hosted separately from the API. Bearer auth does not use cookies, so a permissive CORS policy is safe and keeps the static bundle deployable anywhere.
This commit is contained in:
1 parent
b33eb076c1
commit
54cf807a9b
2 files changed
+19
No files matched your search
@@ -1,6 +1,8 @@
|
||||
package win.taptap.musicmanager
|
||||
|
||||
import io.ktor.http.ContentType
|
||||
import io.ktor.http.HttpHeaders
|
||||
import io.ktor.http.HttpMethod
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.serialization.kotlinx.json.json
|
||||
import io.ktor.server.application.install
|
||||
@@ -9,6 +11,7 @@ import io.ktor.server.netty.Netty
|
||||
import io.ktor.server.plugins.autohead.AutoHeadResponse
|
||||
import io.ktor.server.plugins.calllogging.CallLogging
|
||||
import io.ktor.server.plugins.contentnegotiation.ContentNegotiation
|
||||
import io.ktor.server.plugins.cors.routing.CORS
|
||||
import io.ktor.server.plugins.partialcontent.PartialContent
|
||||
import io.ktor.server.plugins.statuspages.StatusPages
|
||||
import io.ktor.server.request.path
|
||||
@@ -81,6 +84,21 @@ fun main() {
|
||||
},
|
||||
)
|
||||
}
|
||||
// The Wasm client can be hosted separately; bearer auth needs no cookies.
|
||||
install(CORS) {
|
||||
anyHost()
|
||||
allowMethod(HttpMethod.Get)
|
||||
allowMethod(HttpMethod.Post)
|
||||
allowMethod(HttpMethod.Patch)
|
||||
allowMethod(HttpMethod.Delete)
|
||||
allowMethod(HttpMethod.Head)
|
||||
allowMethod(HttpMethod.Options)
|
||||
allowHeader(HttpHeaders.Authorization)
|
||||
allowHeader(HttpHeaders.ContentType)
|
||||
allowHeader(HttpHeaders.Range)
|
||||
allowNonSimpleContentTypes = true
|
||||
maxAgeInSeconds = 3600
|
||||
}
|
||||
install(PartialContent)
|
||||
install(AutoHeadResponse)
|
||||
install(CallLogging)
|
||||
|
||||
Reference in new issue
Block a user