Refactor package structure and add web components.

Reorganized Kotlin package structure under 'nl.astraeus' and removed 'gradle.properties' file. Updated '.gitignore' to exclude 'gradle.properties'. Added new web functionalities including ID generation, websocket and HTTP request handling to support dynamic web content delivery. Adjusted server configuration and modified build version.
This commit is contained in:
2024-12-01 11:59:26 +01:00
parent bf9d72a20c
commit 88d09ecdbf
13 changed files with 245 additions and 42 deletions

View File

@@ -0,0 +1,69 @@
package nl.astraeus.tmpl
import com.zaxxer.hikari.HikariConfig
import io.undertow.Undertow
import io.undertow.UndertowOptions
import io.undertow.predicate.Predicates
import io.undertow.server.handlers.encoding.ContentEncodingRepository
import io.undertow.server.handlers.encoding.EncodingHandler
import io.undertow.server.handlers.encoding.GzipEncodingProvider
import nl.astraeus.logger.Logger
import nl.astraeus.tmpl.db.Database
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
fun main() {
Thread.currentThread().uncaughtExceptionHandler = Thread.UncaughtExceptionHandler { t, e ->
log.warn(e) {
e.message
}
}
Runtime.getRuntime().addShutdownHook(
object : Thread() {
override fun run() {
Database.vacuumDatabase()
Database.closeDatabase()
}
}
)
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"
username = "sa"
password = ""
maximumPoolSize = 25
isAutoCommit = false
validate()
})
val compressionHandler =
EncodingHandler(
ContentEncodingRepository()
.addEncodingHandler(
"gzip",
GzipEncodingProvider(), 50,
Predicates.parse("max-content-size(5)")
)
).setNext(RequestHandler)
val server = Undertow.builder()
.addHttpListener(SERVER_PORT, "localhost")
.setIoThreads(4)
.setHandler(compressionHandler)
.setServerOption(UndertowOptions.SHUTDOWN_TIMEOUT, 1000)
.build()
println("Starting undertow server at port 6007...")
server?.start()
}