Adam Cooper
10/08/2022, 7:26 PMrouting {
static("scripts") {
... // Serve JavaScript files from this endpoint
}
}
But instead of just writing JavaScript, I'd prefer to write Kotlin which is then compiled to JavaScript, and serve those generated files.
I found the full-stack tutorial in the docs, but the server is written in JavaScript and serves a full React application. I am serving a mostly-static webapp with a little bit of JavaScript.jw
10/08/2022, 9:53 PMAdam Cooper
10/08/2022, 10:05 PMhead {
script(type = ScriptType.textJavaScript, src = "/static/scripts/adamcooper-sh.js") {}
}
which does download the script successfully, so that's good. But I am unsure how to load functions from the script.
button(classes = "fa fa-copy wordleCopyButton") {
onClick =
"copyToClipboard(document.getElementById('$solutionID'));"
}
The copyToClipboard
function comes from my compiled JS. It throws a ReferenceError
because it can't find the reference.jw
10/08/2022, 11:17 PMglobalThis
so they're available as top-level functions like you've written there.jw
10/08/2022, 11:18 PMAdam Cooper
10/08/2022, 11:21 PM