mirror of
https://github.com/ViaVersion/VIAaaS.git
synced 2025-01-09 19:48:37 +01:00
use get routing, fixes "response already sent"
This commit is contained in:
parent
9ebae3d7df
commit
6f2c411dbf
@ -5,11 +5,15 @@ import io.ktor.features.*
|
|||||||
import io.ktor.http.*
|
import io.ktor.http.*
|
||||||
import io.ktor.http.cio.websocket.*
|
import io.ktor.http.cio.websocket.*
|
||||||
import io.ktor.http.content.*
|
import io.ktor.http.content.*
|
||||||
|
import io.ktor.response.*
|
||||||
import io.ktor.routing.*
|
import io.ktor.routing.*
|
||||||
|
import io.ktor.util.*
|
||||||
import io.ktor.websocket.*
|
import io.ktor.websocket.*
|
||||||
import kotlinx.coroutines.channels.consumeEach
|
import kotlinx.coroutines.channels.consumeEach
|
||||||
import org.slf4j.event.Level
|
import org.slf4j.event.Level
|
||||||
|
import java.io.File
|
||||||
import java.nio.channels.ClosedChannelException
|
import java.nio.channels.ClosedChannelException
|
||||||
|
import java.nio.file.Path
|
||||||
import java.time.Duration
|
import java.time.Duration
|
||||||
|
|
||||||
class ViaWebApp(val viaWebServer: WebDashboardServer) {
|
class ViaWebApp(val viaWebServer: WebDashboardServer) {
|
||||||
@ -40,11 +44,25 @@ class ViaWebApp(val viaWebServer: WebDashboardServer) {
|
|||||||
install(Compression)
|
install(Compression)
|
||||||
|
|
||||||
routing {
|
routing {
|
||||||
static {
|
get("{path...}") {
|
||||||
default("config/web/index.html")
|
// todo if-modified-since
|
||||||
files("config/web")
|
val relativePath = Path.of(call.parameters.getAll("path")?.joinToString("/") ?: "")
|
||||||
defaultResource("index.html", "web")
|
val index = Path.of("index.html")
|
||||||
resources("web")
|
|
||||||
|
var resource = call.resolveResource(relativePath.toString(), "web")
|
||||||
|
if (resource == null) {
|
||||||
|
resource = call.resolveResource(relativePath.resolve(index).toString(), "web")
|
||||||
|
}
|
||||||
|
|
||||||
|
var file = File("config/web").combineSafe(relativePath)
|
||||||
|
if (file.isDirectory) {
|
||||||
|
file = file.resolve("index.html")
|
||||||
|
}
|
||||||
|
|
||||||
|
when {
|
||||||
|
file.isFile -> call.respondFile(file)
|
||||||
|
resource != null -> call.respond(resource)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
webSocket("/ws") {
|
webSocket("/ws") {
|
||||||
|
Loading…
Reference in New Issue
Block a user