https://kotlinlang.org logo
#http4k
Title
# http4k
r

Reuben Firmin

10/26/2023, 2:24 PM
Hello. I see that hot reload is supported with static resources - is there a way to make it work when serving html from a route? (I'm working on a poc to see whether kotlinx.html is a good fit for our app)
d

dave

10/26/2023, 2:59 PM
Because kotlinx is compiled then it would require some type of listener and watching engine. Http4k doesn't support that out of the box I'm afraid.
j

James Richardson

10/26/2023, 6:18 PM
Using kts might be a good fit for this... its not too hard to make kts hot reload, and using the HttpHandler type would mean that the "interface" to the kts would be really straightforward.
Copy code
import java.io.File
import javax.script.ScriptEngine
import javax.script.ScriptEngineManager

class Scripting() {
    val scriptEngineManager = ScriptEngineManager()
    val engine : ScriptEngine = scriptEngineManager.getEngineByExtension("kts")

    inline fun <reified T> load(file: File):T {
        return engine.eval(file.readText()) as T
    }
}
r

Reuben Firmin

10/26/2023, 6:21 PM
Thanks - I'll try this and report back
j

James Richardson

10/26/2023, 6:22 PM
Last time I did this a few years ago, needed the following dependencies
Copy code
implementation "org.jetbrains.kotlin:kotlin-script-runtime:$kotlinVersion"
    implementation "org.jetbrains.kotlin:kotlin-compiler-embeddable:$kotlinVersion"
    implementation "org.jetbrains.kotlin:kotlin-script-util:$kotlinVersion"
    implementation "org.jetbrains.kotlin:kotlin-scripting-jsr223-embeddable:$kotlinVersion"
    runtime "org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:$kotlinVersion"
But this has probably changed in the interim
3 Views