Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to deploy to Cloudflare, no event handlers registered #4

Open
cgfrost opened this issue Jul 9, 2023 · 1 comment
Open

Fails to deploy to Cloudflare, no event handlers registered #4

cgfrost opened this issue Jul 9, 2023 · 1 comment

Comments

@cgfrost
Copy link

cgfrost commented Jul 9, 2023

Following the instructions in the README results in the following error.

No event handlers were registered. This script does nothing.

Cloudflare accepts two formats for a worker. Service Worker where an event listener for fetch events must be registered or ES modules. This example worker needs to be expanded to include the event listener.

As an aside, the new support for useEsModules() in KotlinJS would be great but it doesn't yet create a module with a default export which Cloudflare requires.

@2001zhaozhao
Copy link

2001zhaozhao commented Oct 14, 2023

I am getting the same issue. Kotlin/JS does not seem to generate the JS file in the format that Cloudflare Workers expects.

Edit:
This is the additional code that I had to add to the example to get it to work:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants