(fix) Konfiguration-Setup Umbau zu SCS

This commit is contained in:
stefan
2025-07-19 14:13:51 +02:00
parent b3f8624aa9
commit e38ab27fbe
18 changed files with 655 additions and 121 deletions
@@ -1,38 +1,30 @@
package at.mocode.gateway
import at.mocode.gateway.config.MigrationSetup
import at.mocode.shared.config.AppConfig
import at.mocode.shared.database.DatabaseConfig
import at.mocode.shared.database.DatabaseFactory
import io.ktor.serialization.kotlinx.json.*
import io.ktor.server.application.*
import io.ktor.server.engine.*
import io.ktor.server.netty.*
import io.ktor.server.plugins.contentnegotiation.*
import io.ktor.serialization.kotlinx.json.*
import io.ktor.server.routing.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
fun main() {
// Konfiguration laden (wird automatisch beim ersten Zugriff auf AppConfig initialisiert)
val config = AppConfig
// Datenbank initialisieren
val databaseConfig = DatabaseConfig.fromEnv()
DatabaseFactory.init(databaseConfig)
DatabaseFactory.init(config.database)
// Migrationen ausführen
MigrationSetup.runMigrations()
// Server starten
embeddedServer(Netty, port = System.getenv("API_PORT")?.toIntOrNull() ?: 8081) {
configureApplication()
embeddedServer(Netty, port = config.server.port, host = config.server.host) {
module()
}.start(wait = true)
}
fun Application.configureApplication() {
install(ContentNegotiation) {
json()
}
routing {
get("/health") {
call.respond(mapOf("status" to "OK"))
}
}
}
@@ -0,0 +1,53 @@
package at.mocode.gateway
import at.mocode.shared.config.AppConfig
import io.ktor.http.*
import io.ktor.serialization.kotlinx.json.*
import io.ktor.server.application.*
import io.ktor.server.plugins.calllogging.*
import io.ktor.server.plugins.contentnegotiation.*
import io.ktor.server.plugins.cors.routing.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
fun Application.module() {
val config = AppConfig
// ContentNegotiation installieren
install(ContentNegotiation) {
json()
}
// CORS installieren, wenn aktiviert
if (config.server.cors.enabled) {
install(CORS) {
if (config.server.cors.allowedOrigins.contains("*")) {
anyHost()
} else {
config.server.cors.allowedOrigins.forEach { allowHost(it, schemes = listOf("http", "https")) }
}
allowHeader(HttpHeaders.ContentType)
allowHeader(HttpHeaders.Authorization)
allowMethod(HttpMethod.Options)
allowMethod(HttpMethod.Get)
allowMethod(HttpMethod.Post)
allowMethod(HttpMethod.Put)
allowMethod(HttpMethod.Delete)
}
}
// Call-Logging installieren
if (config.logging.logRequests) {
install(CallLogging)
}
routing {
// Hauptrouten
get("/") {
call.respondText(
"${config.appInfo.name} API v${config.appInfo.version} (${config.environment})",
ContentType.Text.Plain
)
}
}
}