Update readme

This commit is contained in:
2026-01-04 00:37:57 +08:00
parent a8a8004ac8
commit 94a486a505
2 files changed
+56 -2

No files matched your search

+27
View File
@@ -137,6 +137,33 @@ fun handleRequest(request: Request): Promise<Response> = GlobalScope.promise {
Cloudflare worker is not a standard nodejs environment, do http requests must
use fetch api(not `window.fetch`, this is browser api), use `cn.rtast.cfworker.client.fetch` instead,
# Websocket
Only websocket server is supported
> ktor like expression
```kotlin
@JsExport
fun handleRequest(request: Request): Promise<Response> = GlobalScope.promise {
val server = WorkerApplication().apply {
route("/") {
respondText("Hello kotlin cloudflare worker")
}
webSocket("/ws") {
onMessage {
println(it.readText())
}
onClose {
}
}
}
return@promise server.handle(request)
}
```
# ByteArray and ByteBuffer cast
Kotlin cloudflare worker provided api to mutual conversion,