Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ After setting up Kotlin per the linked instructions above,
./gradlew :compileProductionExecutableKotlinJs
```

That will compile your code and package it into a JavaScript executable, after which you can run `wrangler publish` to push it to Cloudflare.
That will compile your code and package it into a JavaScript executable, after which you can run `wrangler deploy` to push it to Cloudflare.

```
wrangler publish build/js/packages/kotlin-worker-hello-world/kotlin/kotlin-worker-hello-world.js
wrangler deploy build/js/packages/kotlin-worker-hello-world/kotlin/kotlin-worker-hello-world.js
```

For more information on interop between Kotlin and Javascript, see the [Kotlin docs](https://kotlinlang.org/docs/reference/js-interop.html). Regarding coroutines, see [this issue and workaround](https://github.com/cloudflare/kotlin-worker-hello-world/issues/2)
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
kotlin("js") version "1.7.10"
kotlin("multiplatform") version "2.2.10"
}

group = "org.example"
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
10 changes: 10 additions & 0 deletions src/main/kotlin/main.kt → src/jsMain/kotlin/main.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import org.w3c.dom.events.EventListener
import org.w3c.fetch.Request
import org.w3c.fetch.Response
import org.w3c.fetch.ResponseInit

fun main() {
@Suppress("UNUSED_VARIABLE")
val eventListener = EventListener {event ->
event.asDynamic().respondWith(fetch(event.asDynamic().request as Request))
Unit
}
js("addEventListener('fetch', eventListener)")
}

@OptIn(ExperimentalJsExport::class)
@JsExport
fun fetch(request: Request) : Response {
Expand Down
File renamed without changes.