Skip to content

Cloudflare worker with KotlinJS 1.9.0

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

griffio/kotlin-worker-hello-world

 
 

Repository files navigation

Kotlin hello world for Cloudflare Workers

Your Kotlin code in main.kt, running on Cloudflare Workers

In addition to Wrangler you will need to install Kotlin, including a JDK and support for Gradle projects. The easiest way to do this is using the free Community Edition of IntelliJ IDEA.

Wrangler 3.9.0

To generate using wrangler

Note: This still uses Service Workers API instead of the newer module syntax

Kotlin JS doesn't support module syntax with default export yet, so we need to use the Service Workers API for now.

// new module syntax with default not supported yet in Kotlin JS 
export default {
   async fetch(request, env, ctx) {
       return new Response('Hello World!');
   },
};
wrangler generate projectname https://github.com/griffio/kotlin-worker-hello-world

You need to register a workers.dev subdomain before running the dev command in remote mode

Further documentation for Wrangler can be found here.

Gradle

After setting up Kotlin per the linked instructions above,

cd projectname
./gradlew build

That will compile your code and package it into build/distributions/kotlin-worker-hello-world.js, after which you can run wrangler deploy build/distributions/kotlin-worker-hello-world.js to push it to Cloudflare.

About

Cloudflare worker with KotlinJS 1.9.0

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Languages

  • Kotlin 82.8%
  • HTML 17.2%