generated from rnentjes/kotlin-server-web-empty
Refactor placeholder constants into dedicated file
Moved REPO_NAME and related constants into Placeholders.kt to improve code organization and maintainability. The code now dynamically references these constants where needed, simplifying updates and ensuring consistency across modules. Updated relevant imports and references to accommodate these changes.
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
# Repo name
|
||||
settings.gradle.kts
|
||||
**.kt
|
||||
src/jvmMain/kotlin/nl/astraeus/tmpl/Placeholders.kt
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
|
||||
}
|
||||
val REPO_NAME = "template"
|
||||
val REPO_NAME = "dummy so the gitea template compiles, please remove"
|
||||
rootProject.name = "kotlin-server-web-undertow"
|
||||
|
||||
@@ -13,8 +13,6 @@ import nl.astraeus.tmpl.web.RequestHandler
|
||||
|
||||
val log = Logger()
|
||||
|
||||
val REPO_NAME = "dummy so the gitea template compiles, please remove"
|
||||
|
||||
val SERVER_PORT = 7001
|
||||
val JDBC_PORT = 8001
|
||||
|
||||
@@ -37,7 +35,7 @@ fun main() {
|
||||
Class.forName("nl.astraeus.jdbc.Driver")
|
||||
Database.initialize(HikariConfig().apply {
|
||||
driverClassName = "nl.astraeus.jdbc.Driver"
|
||||
jdbcUrl = "jdbc:stat:webServerPort=$JDBC_PORT:jdbc:sqlite:data/${REPO_NAME}.db"
|
||||
jdbcUrl = "jdbc:stat:webServerPort=$JDBC_PORT:jdbc:sqlite:data/$repoName.db"
|
||||
username = "sa"
|
||||
password = ""
|
||||
maximumPoolSize = 25
|
||||
|
||||
7
src/jvmMain/kotlin/nl/astraeus/tmpl/Placeholders.kt
Normal file
7
src/jvmMain/kotlin/nl/astraeus/tmpl/Placeholders.kt
Normal file
@@ -0,0 +1,7 @@
|
||||
package nl.astraeus.tmpl
|
||||
|
||||
val REPO_NAME = "dummy so the gitea template compiles, please remove"
|
||||
|
||||
val pageTitle = "${REPO_NAME}"
|
||||
val itemUrl = "${REPO_NAME}"
|
||||
val repoName = "${REPO_NAME}"
|
||||
@@ -8,6 +8,8 @@ import kotlinx.html.script
|
||||
import kotlinx.html.stream.appendHTML
|
||||
import kotlinx.html.title
|
||||
import nl.astraeus.tmpl.REPO_NAME
|
||||
import nl.astraeus.tmpl.pageTitle
|
||||
import nl.astraeus.tmpl.repoName
|
||||
|
||||
fun generateIndex(patch: String?): String {
|
||||
val result = StringBuilder();
|
||||
@@ -15,17 +17,17 @@ fun generateIndex(patch: String?): String {
|
||||
if (patch == null) {
|
||||
result.appendHTML(true).html {
|
||||
head {
|
||||
title("${REPO_NAME}")
|
||||
title(pageTitle)
|
||||
//link("/css/all.min.css", "stylesheet")
|
||||
}
|
||||
body {
|
||||
script(src = "/${REPO_NAME}.js") {}
|
||||
script(src = "/$repoName.js") {}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
result.appendHTML(true).html {
|
||||
head {
|
||||
title("${REPO_NAME}")
|
||||
title(pageTitle)
|
||||
meta {
|
||||
httpEquiv = "refresh"
|
||||
content = "0; url=/$itemUrl/$patch"
|
||||
|
||||
@@ -5,11 +5,10 @@ import io.undertow.server.HttpServerExchange
|
||||
import io.undertow.server.handlers.PathHandler
|
||||
import io.undertow.server.handlers.resource.PathResourceManager
|
||||
import io.undertow.server.handlers.resource.ResourceHandler
|
||||
import nl.astraeus.tmpl.itemUrl
|
||||
import java.nio.file.Paths
|
||||
import kotlin.text.startsWith
|
||||
|
||||
val itemUrl = "blaat"
|
||||
|
||||
object IndexHandler : HttpHandler {
|
||||
override fun handleRequest(exchange: HttpServerExchange) {
|
||||
if (exchange.requestPath.startsWith("/$itemUrl/")) {
|
||||
@@ -29,7 +28,7 @@ object RequestHandler : HttpHandler {
|
||||
init {
|
||||
pathHandler.addExactPath("/", IndexHandler)
|
||||
pathHandler.addExactPath("/index.html", IndexHandler)
|
||||
pathHandler.addPrefixPath("/song", IndexHandler)
|
||||
pathHandler.addPrefixPath("/$itemUrl", IndexHandler)
|
||||
pathHandler.addExactPath("/ws", WebsocketConnectHandler)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user