diff --git a/server/src/main/kotlin/com/pixelized/server/lwa/server/Server.kt b/server/src/main/kotlin/com/pixelized/server/lwa/server/Server.kt index 9bd0813..b279a0e 100644 --- a/server/src/main/kotlin/com/pixelized/server/lwa/server/Server.kt +++ b/server/src/main/kotlin/com/pixelized/server/lwa/server/Server.kt @@ -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.protocol.websocket.SocketMessage import com.pixelized.shared.lwa.sharedModuleDependencies +import com.pixelized.shared.lwa.utils.PathProvider import io.ktor.serialization.kotlinx.json.json import io.ktor.server.application.install 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.NettyApplicationEngine 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.plugin.Koin import serverModuleDependencies +import java.io.File import kotlin.time.Duration.Companion.seconds // https://ktor.io/docs/server-websockets.html#handle-multiple-session @@ -91,6 +95,7 @@ class LocalServer { val json by inject() val engine by inject() + val pathProvider by inject() install(ContentNegotiation) { json(json) @@ -140,6 +145,11 @@ class LocalServer { } } ) + staticFiles( + remotePath = "/resources", + dir = File(pathProvider.resourcesPath()), + index = null, + ) route(path = "/campaign") { get( path = "", diff --git a/shared/src/commonMain/kotlin/com/pixelized/shared/lwa/utils/PathProvider.kt b/shared/src/commonMain/kotlin/com/pixelized/shared/lwa/utils/PathProvider.kt index a8ab06a..c953f15 100644 --- a/shared/src/commonMain/kotlin/com/pixelized/shared/lwa/utils/PathProvider.kt +++ b/shared/src/commonMain/kotlin/com/pixelized/shared/lwa/utils/PathProvider.kt @@ -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( os: OperatingSystem = this.operatingSystem, app: String = this.appName,