Skip to content

Commit

Permalink
Update served webUI after update
Browse files Browse the repository at this point in the history
The "index.html" file was served as a single page via "addSinglePageRoot".
This apparently caches the file and will cause issues if the actual file got changed.
After a webUI update, the outdated "index.html" file pointed to an "index.js" file which did not exist anymore.
Without restarting the server, it was not possible to get the updated "index.html".

What's weird is, that the files added via "addStaticFiles" are not cached.
Thus, after the webUI update, opening "/" in the browser returned the updated file and everything worked, while every other path e.g. "/library" returned the outdated file (due to being served by "addSinglePageHandler") causing a white screen
  • Loading branch information
schroda committed Nov 7, 2023
1 parent b303291 commit bf3826e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,19 @@ object JavalinSetup {
val app =
Javalin.create { config ->
if (serverConfig.webUIEnabled.value) {
val serveWebUI = {
config.addSinglePageRoot("/", applicationDirs.webUIRoot + "/index.html", Location.EXTERNAL)
}
WebInterfaceManager.setServeWebUI(serveWebUI)

runBlocking {
WebInterfaceManager.setupWebUI()
}

logger.info { "Serving web static files for ${serverConfig.webUIFlavor.value}" }
config.addStaticFiles(applicationDirs.webUIRoot, Location.EXTERNAL)
config.addSinglePageRoot("/", applicationDirs.webUIRoot + "/index.html", Location.EXTERNAL)
serveWebUI()

config.registerPlugin(OpenApiPlugin(getOpenApiOptions()))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ object WebInterfaceManager {
)
}

private var serveWebUI: () -> Unit = {}

fun setServeWebUI(serveWebUI: () -> Unit) {
this.serveWebUI = serveWebUI
}

private fun isAutoUpdateEnabled(): Boolean {
return serverConfig.webUIUpdateCheckInterval.value.toInt() != 0
}
Expand Down Expand Up @@ -566,6 +572,8 @@ object WebInterfaceManager {
log.info { "Extracting WebUI zip Done." }

emitStatus(version, FINISHED, 100)

serveWebUI()
} catch (e: Exception) {
emitStatus(version, ERROR, 0)
throw e
Expand Down

0 comments on commit bf3826e

Please sign in to comment.