- server config outsourced
- test integrated
This commit is contained in:
parent
44cef36d00
commit
b999cb5832
103
analysis.md
Normal file
103
analysis.md
Normal file
|
|
@ -0,0 +1,103 @@
|
||||||
|
# Analysis of Meldestelle Project Setups
|
||||||
|
|
||||||
|
## Project Overview
|
||||||
|
Meldestelle is a Kotlin Multiplatform project targeting three platforms:
|
||||||
|
1. Web (Kotlin/Wasm)
|
||||||
|
2. Desktop (JVM)
|
||||||
|
3. Server (Ktor on JVM)
|
||||||
|
|
||||||
|
The project uses a shared module for common code and platform-specific implementations.
|
||||||
|
|
||||||
|
## Shared Module Setup
|
||||||
|
- **Purpose**: Contains code shared between all platforms
|
||||||
|
- **Configuration**:
|
||||||
|
- Uses Kotlin Multiplatform plugin
|
||||||
|
- Targets JVM and Wasm/JS
|
||||||
|
- No explicit dependencies in commonMain
|
||||||
|
- **Key Components**:
|
||||||
|
- `Constants.kt`: Defines server port (8080)
|
||||||
|
- `Greeting.kt`: Common greeting functionality
|
||||||
|
- `Platform.kt`: Interface with expect/actual pattern for platform-specific implementations
|
||||||
|
- **Platform Implementations**:
|
||||||
|
- JVM: Returns "Java [version]"
|
||||||
|
- Wasm/JS: Returns "Web with Kotlin/Wasm"
|
||||||
|
|
||||||
|
## Web (Wasm/JS) Setup
|
||||||
|
- **Configuration**:
|
||||||
|
- Uses experimental Wasm/JS target
|
||||||
|
- Configures webpack for browser output
|
||||||
|
- Sets up static paths for debugging
|
||||||
|
- **UI Implementation**:
|
||||||
|
- Uses ComposeViewport to attach to document body
|
||||||
|
- Uses common App composable
|
||||||
|
- **Resources**:
|
||||||
|
- Simple HTML template with title "Meldestelle"
|
||||||
|
- Basic CSS for full viewport styling
|
||||||
|
- Empty JS file (likely generated during build)
|
||||||
|
- **Build Output**: Generates composeApp.js
|
||||||
|
|
||||||
|
## Desktop Setup
|
||||||
|
- **Configuration**:
|
||||||
|
- Uses JVM target
|
||||||
|
- Configures native distributions (DMG, MSI, DEB)
|
||||||
|
- Sets main class to "at.mocode.MainKt"
|
||||||
|
- **UI Implementation**:
|
||||||
|
- Uses Compose for Desktop's Window API
|
||||||
|
- Sets window title to "Meldestelle"
|
||||||
|
- Uses common App composable
|
||||||
|
- **Dependencies**:
|
||||||
|
- Compose Desktop for current OS
|
||||||
|
- Kotlinx Coroutines Swing
|
||||||
|
|
||||||
|
## Server Setup
|
||||||
|
- **Configuration**:
|
||||||
|
- Uses Kotlin JVM plugin
|
||||||
|
- Uses Ktor plugin
|
||||||
|
- Sets main class to "at.mocode.ApplicationKt"
|
||||||
|
- **Implementation**:
|
||||||
|
- Uses Ktor with Netty engine
|
||||||
|
- Runs on port 8080 (from shared Constants)
|
||||||
|
- Simple GET endpoint at "/"
|
||||||
|
- Returns "Ktor: [greeting]" using shared Greeting class
|
||||||
|
- **Dependencies**:
|
||||||
|
- Shared module
|
||||||
|
- Logback for logging
|
||||||
|
- Ktor server core and Netty
|
||||||
|
- Testing dependencies
|
||||||
|
|
||||||
|
## Common UI
|
||||||
|
- **Implementation**:
|
||||||
|
- Simple Material Design UI
|
||||||
|
- Button to toggle content visibility
|
||||||
|
- Shows Compose Multiplatform logo and greeting when visible
|
||||||
|
- Uses platform-specific greeting implementation
|
||||||
|
|
||||||
|
## Observations and Recommendations
|
||||||
|
|
||||||
|
### Strengths
|
||||||
|
1. **Code Sharing**: Effectively shares code between platforms
|
||||||
|
2. **Platform Abstraction**: Good use of expect/actual pattern
|
||||||
|
3. **Build Configuration**: Clean separation of build configurations
|
||||||
|
|
||||||
|
### Potential Improvements
|
||||||
|
1. **Dependencies**: The shared module has no explicit dependencies in commonMain
|
||||||
|
2. **Documentation**: Limited inline documentation
|
||||||
|
3. **Testing**: No visible tests for client-side code
|
||||||
|
4. **Resource Handling**: Basic resource handling, could be expanded
|
||||||
|
5. **Error Handling**: No visible error handling in server endpoints
|
||||||
|
6. **Configuration**: Hard-coded server port, could use configuration file
|
||||||
|
7. **Security**: No visible security measures in server setup
|
||||||
|
8. **Logging**: Minimal logging configuration
|
||||||
|
|
||||||
|
### Recommendations
|
||||||
|
1. Add proper dependency management in shared module
|
||||||
|
2. Implement comprehensive testing for all platforms
|
||||||
|
3. Add proper error handling in server endpoints
|
||||||
|
4. Use configuration files for server settings
|
||||||
|
5. Implement security measures for server (CORS, authentication)
|
||||||
|
6. Enhance logging configuration
|
||||||
|
7. Add more inline documentation
|
||||||
|
8. Consider adding a CI/CD pipeline configuration
|
||||||
|
|
||||||
|
## Conclusion
|
||||||
|
The Meldestelle project demonstrates a well-structured Kotlin Multiplatform application targeting Web, Desktop, and Server. The project effectively shares code between platforms while allowing for platform-specific implementations. With some improvements in areas like testing, error handling, and configuration, the project could be more robust and production-ready.
|
||||||
|
|
@ -8,6 +8,7 @@ ktor = "3.1.2"
|
||||||
ktor-tests = "2.3.13"
|
ktor-tests = "2.3.13"
|
||||||
logback = "1.5.18"
|
logback = "1.5.18"
|
||||||
junit-jupiter = "5.12.0"
|
junit-jupiter = "5.12.0"
|
||||||
|
junit-jupiter-version = "5.8.1"
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
|
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
|
||||||
|
|
@ -24,6 +25,10 @@ ktor-server-tests = { module = "io.ktor:ktor-server-tests-jvm", version.ref = "k
|
||||||
junit-jupiter = { group = "org.junit.jupiter", name = "junit-jupiter", version.ref = "junit-jupiter" }
|
junit-jupiter = { group = "org.junit.jupiter", name = "junit-jupiter", version.ref = "junit-jupiter" }
|
||||||
jupiter-junit-jupiter = { group = "org.junit.jupiter", name = "junit-jupiter", version.ref = "junit-jupiter" }
|
jupiter-junit-jupiter = { group = "org.junit.jupiter", name = "junit-jupiter", version.ref = "junit-jupiter" }
|
||||||
|
|
||||||
|
# ... andere libraries ...
|
||||||
|
ktor-server-config-yaml = { module = "io.ktor:ktor-server-config-yaml", version.ref = "ktor" }
|
||||||
|
junit-junit-jupiter = { group = "org.junit.jupiter", name = "junit-jupiter", version.ref = "junit-jupiter-version" }
|
||||||
|
|
||||||
[plugins]
|
[plugins]
|
||||||
composeMultiplatform = { id = "org.jetbrains.compose", version.ref = "compose-multiplatform" }
|
composeMultiplatform = { id = "org.jetbrains.compose", version.ref = "compose-multiplatform" }
|
||||||
composeCompiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
|
composeCompiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
|
||||||
|
|
|
||||||
|
|
@ -20,4 +20,6 @@ dependencies {
|
||||||
testImplementation(libs.kotlin.test.junit)
|
testImplementation(libs.kotlin.test.junit)
|
||||||
testImplementation(libs.junit.jupiter)
|
testImplementation(libs.junit.jupiter)
|
||||||
testImplementation(libs.jupiter.junit.jupiter)
|
testImplementation(libs.jupiter.junit.jupiter)
|
||||||
|
implementation(libs.ktor.server.config.yaml)
|
||||||
|
testImplementation(libs.junit.junit.jupiter)
|
||||||
}
|
}
|
||||||
|
|
@ -1,14 +1,12 @@
|
||||||
package at.mocode
|
package at.mocode
|
||||||
|
|
||||||
import io.ktor.server.application.*
|
import io.ktor.server.application.*
|
||||||
import io.ktor.server.engine.*
|
|
||||||
import io.ktor.server.netty.*
|
import io.ktor.server.netty.*
|
||||||
import io.ktor.server.response.*
|
import io.ktor.server.response.*
|
||||||
import io.ktor.server.routing.*
|
import io.ktor.server.routing.*
|
||||||
|
|
||||||
fun main() {
|
fun main(args: Array<String>) {
|
||||||
embeddedServer(Netty, port = SERVER_PORT, host = "0.0.0.0", module = Application::module)
|
EngineMain.main(args)
|
||||||
.start(wait = true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Application.module() {
|
fun Application.module() {
|
||||||
|
|
|
||||||
19
server/src/main/resources/application.yaml
Normal file
19
server/src/main/resources/application.yaml
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Grundkonfiguration für Ktor in YAML
|
||||||
|
|
||||||
|
ktor:
|
||||||
|
deployment:
|
||||||
|
# Der Port, auf dem der Server lauschen soll
|
||||||
|
port: 8080
|
||||||
|
# port: ${PORT:8080} # Alternative: Nutzt Env-Variable PORT, sonst 8080
|
||||||
|
# Optional für Entwicklung: Server bei Änderungen neu laden
|
||||||
|
# watch:
|
||||||
|
# - classes
|
||||||
|
# - resources
|
||||||
|
|
||||||
|
application:
|
||||||
|
# Hier wird Ktor gesagt, welche Funktion die Konfiguration enthält
|
||||||
|
# PASSE DEN PFAD AN, falls deine Application.kt oder module() anders heißt/liegt!
|
||||||
|
modules:
|
||||||
|
- at.mocode.ApplicationKt.module
|
||||||
|
# Wenn Application.kt direkt unter at.mocode liegt:
|
||||||
|
# - at.mocode.ApplicationKt.module
|
||||||
|
|
@ -1,15 +1,27 @@
|
||||||
package at.mocode
|
package at.mocode
|
||||||
|
|
||||||
import org.junit.jupiter.api.Assertions.*
|
import io.ktor.client.request.*
|
||||||
import org.junit.jupiter.api.Test
|
import io.ktor.client.statement.*
|
||||||
|
import io.ktor.http.*
|
||||||
|
import io.ktor.server.testing.* // Wichtig für testApplication
|
||||||
|
import kotlin.test.* // Wichtig für assertEquals, assertTrue etc.
|
||||||
|
|
||||||
class ApplicationTest {
|
class ApplicationTest {
|
||||||
@Test
|
|
||||||
fun main() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun module() {
|
fun testRootRoute() = testApplication {
|
||||||
|
application {
|
||||||
|
module() // Ruft deine Konfigurationsfunktion auf
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sendet eine GET-Anfrage an "/" innerhalb der Test-App
|
||||||
|
val response = client.get("/")
|
||||||
|
|
||||||
|
// Überprüfungen (Assertions)
|
||||||
|
assertEquals(HttpStatusCode.OK, response.status, "Status Code should be OK")
|
||||||
|
val content = response.bodyAsText() // Holt den HTML-Body als Text
|
||||||
|
assertTrue(content.contains("Ktor: Hello, Java 21.0.6!"), "Welcome message missing")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,3 +1 @@
|
||||||
package at.mocode
|
package at.mocode
|
||||||
|
|
||||||
const val SERVER_PORT = 8080
|
|
||||||
Loading…
Reference in New Issue
Block a user