From 8549c68cfcf4caabb696152f36facc074129ebcf Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Wed, 1 May 2019 15:33:42 +0200 Subject: Added deployment features and functionality Co-authored-by: LarsVomMars --- src/main/kotlin/App.kt | 27 ++++++++++++++++++++++++--- src/main/kotlin/DatabaseController.kt | 4 ++-- src/main/resources/js/files.js | 1 + 3 files changed, 27 insertions(+), 5 deletions(-) (limited to 'src/main') diff --git a/src/main/kotlin/App.kt b/src/main/kotlin/App.kt index 49cc553..1aa150b 100644 --- a/src/main/kotlin/App.kt +++ b/src/main/kotlin/App.kt @@ -9,8 +9,6 @@ import io.javalin.rendering.* import io.javalin.rendering.template.TemplateUtil.model import io.javalin.security.* import io.javalin.security.SecurityUtil.roles -import io.javalin.staticfiles.* -import java.io.* import java.net.* import java.util.logging.* @@ -22,7 +20,6 @@ private val log = Logger.getLogger("App.kt") fun main() { val app = Javalin.create().apply { - enableStaticFiles("${File(".").absolutePath}/src/main/resources/", Location.EXTERNAL) port(7000) accessManager { handler, ctx, permittedRoles -> roleManager(handler, ctx, permittedRoles) } }.start() @@ -43,6 +40,30 @@ fun main() { if (URI(ctx.url()).normalize().toString() != ctx.url()) ctx.redirect(URI(ctx.url()).normalize().toString()) } + /** + * Renders the static resources (important for deployed jar files) + */ + get( + "/css/*", { ctx -> + ctx.contentType("text/css") + ctx.result(Thread.currentThread().contextClassLoader.getResourceAsStream("css/" + ctx.splat(0))) + }, + roles(Roles.GUEST) + ) + get( + "/js/*", { ctx -> + ctx.contentType("text/js") + ctx.result(Thread.currentThread().contextClassLoader.getResourceAsStream("js/" + ctx.splat(0))) + }, + roles(Roles.GUEST) + ) + get( + "/fonts/*", { ctx -> + ctx.result(Thread.currentThread().contextClassLoader.getResourceAsStream("fonts/" + ctx.splat(0))) + }, + roles(Roles.GUEST) + ) + /** * Main page */ diff --git a/src/main/kotlin/DatabaseController.kt b/src/main/kotlin/DatabaseController.kt index dbb41ba..cce9601 100644 --- a/src/main/kotlin/DatabaseController.kt +++ b/src/main/kotlin/DatabaseController.kt @@ -64,8 +64,8 @@ class DatabaseController(dbFileLocation: String = "main.db") { */ object General : Table() { val id = integer("id").autoIncrement().primaryKey() - val initialUse = bool("initialUse").default(true).primaryKey() - val isSetup = bool("isSetup").default(false).primaryKey() + val initialUse = bool("initialUse").default(true) + val isSetup = bool("isSetup").default(false) } init { diff --git a/src/main/resources/js/files.js b/src/main/resources/js/files.js index d8755cb..de52635 100644 --- a/src/main/resources/js/files.js +++ b/src/main/resources/js/files.js @@ -186,6 +186,7 @@ function setListeners() { }) }); } + // deletion button document.querySelectorAll(".delete").forEach(element => { element.addEventListener("click", e => { -- cgit v1.2.3