Hello. I see that hot reload is supported with sta...
# http4k
r
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
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
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
Thanks - I'll try this and report back
j
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