Add static resource to the server.
This commit is contained in:
parent
2b09126650
commit
1c9b1c49b1
2 changed files with 20 additions and 0 deletions
|
|
@ -45,10 +45,13 @@ import com.pixelized.server.lwa.server.rest.tag.getItemTags
|
||||||
import com.pixelized.shared.lwa.SERVER_PORT
|
import com.pixelized.shared.lwa.SERVER_PORT
|
||||||
import com.pixelized.shared.lwa.protocol.websocket.SocketMessage
|
import com.pixelized.shared.lwa.protocol.websocket.SocketMessage
|
||||||
import com.pixelized.shared.lwa.sharedModuleDependencies
|
import com.pixelized.shared.lwa.sharedModuleDependencies
|
||||||
|
import com.pixelized.shared.lwa.utils.PathProvider
|
||||||
import io.ktor.serialization.kotlinx.json.json
|
import io.ktor.serialization.kotlinx.json.json
|
||||||
import io.ktor.server.application.install
|
import io.ktor.server.application.install
|
||||||
import io.ktor.server.engine.EmbeddedServer
|
import io.ktor.server.engine.EmbeddedServer
|
||||||
import io.ktor.server.engine.embeddedServer
|
import io.ktor.server.engine.embeddedServer
|
||||||
|
import io.ktor.server.http.content.staticFiles
|
||||||
|
import io.ktor.server.http.content.staticResources
|
||||||
import io.ktor.server.netty.Netty
|
import io.ktor.server.netty.Netty
|
||||||
import io.ktor.server.netty.NettyApplicationEngine
|
import io.ktor.server.netty.NettyApplicationEngine
|
||||||
import io.ktor.server.plugins.contentnegotiation.ContentNegotiation
|
import io.ktor.server.plugins.contentnegotiation.ContentNegotiation
|
||||||
|
|
@ -70,6 +73,7 @@ import kotlinx.serialization.json.Json
|
||||||
import org.koin.ktor.ext.inject
|
import org.koin.ktor.ext.inject
|
||||||
import org.koin.ktor.plugin.Koin
|
import org.koin.ktor.plugin.Koin
|
||||||
import serverModuleDependencies
|
import serverModuleDependencies
|
||||||
|
import java.io.File
|
||||||
import kotlin.time.Duration.Companion.seconds
|
import kotlin.time.Duration.Companion.seconds
|
||||||
|
|
||||||
// https://ktor.io/docs/server-websockets.html#handle-multiple-session
|
// https://ktor.io/docs/server-websockets.html#handle-multiple-session
|
||||||
|
|
@ -91,6 +95,7 @@ class LocalServer {
|
||||||
|
|
||||||
val json by inject<Json>()
|
val json by inject<Json>()
|
||||||
val engine by inject<Engine>()
|
val engine by inject<Engine>()
|
||||||
|
val pathProvider by inject<PathProvider>()
|
||||||
|
|
||||||
install(ContentNegotiation) {
|
install(ContentNegotiation) {
|
||||||
json(json)
|
json(json)
|
||||||
|
|
@ -140,6 +145,11 @@ class LocalServer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
staticFiles(
|
||||||
|
remotePath = "/resources",
|
||||||
|
dir = File(pathProvider.resourcesPath()),
|
||||||
|
index = null,
|
||||||
|
)
|
||||||
route(path = "/campaign") {
|
route(path = "/campaign") {
|
||||||
get(
|
get(
|
||||||
path = "",
|
path = "",
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,16 @@ class PathProvider(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun resourcesPath(
|
||||||
|
os: OperatingSystem = this.operatingSystem,
|
||||||
|
app: String = this.appName,
|
||||||
|
): String {
|
||||||
|
return when (os) {
|
||||||
|
OperatingSystem.Windows -> "${storePath(os = os, app = app)}resources\\"
|
||||||
|
OperatingSystem.Macintosh -> "${storePath(os = os, app = app)}resources/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun imagesStorePath(
|
fun imagesStorePath(
|
||||||
os: OperatingSystem = this.operatingSystem,
|
os: OperatingSystem = this.operatingSystem,
|
||||||
app: String = this.appName,
|
app: String = this.appName,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue