Skip to content

Commit 9f43339

Browse files
committed
chore: Resolve ktor deprecations
The old style of resource serving is deprecated, so clean up the logic by moving the JS file to the web folder and defining it all in one line. This means we can avoid doing the weird renaming and script fill passing.
1 parent 3e6539c commit 9f43339

4 files changed

Lines changed: 8 additions & 12 deletions

File tree

build.gradle.kts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,12 @@ tasks {
177177
named<AbstractCopyTask>("jvmProcessResources") {
178178
duplicatesStrategy = DuplicatesStrategy.INCLUDE
179179

180-
from(webpackTask.flatMap { it.mainOutputFile })
180+
from(webpackTask.flatMap { it.mainOutputFile }) {
181+
into("web/js")
182+
include("*.js", "*.js.map")
183+
}
181184

182185
val configProperties = objects.mapProperty(String::class, String::class)
183-
configProperties.put("jsScriptFile", "${rootProject.name}.js")
184186
configProperties.put(
185187
"miniMessageVersion",
186188
libs.adventure.minimessage.map { it.versionConstraint.requiredVersion },

src/commonMain/resources/web/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<meta name="msapplication-TileColor" content="#603cba">
1414
<meta name="theme-color" content="#ffffff">
1515
<title>MiniMessage Viewer | Edit MiniMessage easily online</title>
16-
<!--suppress HtmlUnknownTarget --> <script src="js/main.js" defer></script>
16+
<!--suppress HtmlUnknownTarget --> <script src="js/adventure-webui.js" defer></script>
1717
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.3/css/bulma.min.css"
1818
integrity="sha256-UDtbUHqpVVfXmdJcQVU/bfDEr9xldf3Dbd0ShD0Uf/Y=" crossorigin="anonymous">
1919
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma-prefers-dark@0.1.0-beta.1/css/bulma-prefers-dark.min.css"

src/jvmMain/kotlin/net/kyori/adventure/webui/jvm/minimessage/MiniMessage.kt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import io.ktor.server.http.content.defaultResource
66
import io.ktor.server.http.content.resource
77
import io.ktor.server.http.content.resources
88
import io.ktor.server.http.content.static
9+
import io.ktor.server.http.content.staticFiles
910
import io.ktor.server.http.content.staticResources
1011
import io.ktor.server.request.receiveText
1112
import io.ktor.server.response.respondText
@@ -55,6 +56,7 @@ import net.kyori.adventure.webui.websocket.Placeholders
5556
import net.kyori.adventure.webui.websocket.Response
5657
import java.time.Instant
5758
import net.kyori.adventure.webui.jvm.minimessage.hook.SHADOW_COLOR_RENDER_HOOK
59+
import java.io.File
5860

5961
private val startedAt = Instant.now()
6062

@@ -102,14 +104,7 @@ public fun Application.miniMessage() {
102104

103105
routing {
104106
// define static path to resources
105-
static("") {
106-
resources("web")
107-
defaultResource("web/index.html")
108-
109-
val script = this@miniMessage.getConfigString("jsScriptFile")
110-
resource("js/main.js", script)
111-
resource("js/$script.map", "$script.map")
112-
}
107+
staticResources("/", "web")
113108

114109
// set up other routing
115110
route(URL_API) {

src/jvmMain/resources/application.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ ktor {
1111
}
1212

1313
config {
14-
jsScriptFile = "$jsScriptFile"
1514
miniMessageVersion = "$miniMessageVersion"
1615
commitHash = "$commitHash"
1716
bytebinInstance = "https://bytebin.lucko.me"

0 commit comments

Comments
 (0)