diff --git a/app/src/main/kotlin/net/h34t/filemure/Server.kt b/app/src/main/kotlin/net/h34t/filemure/Server.kt index 2c6f1b6..a9c19f2 100644 --- a/app/src/main/kotlin/net/h34t/filemure/Server.kt +++ b/app/src/main/kotlin/net/h34t/filemure/Server.kt @@ -9,15 +9,18 @@ import org.eclipse.jetty.server.session.DefaultSessionCache import org.eclipse.jetty.server.session.FileSessionDataStore import org.eclipse.jetty.server.session.SessionHandler import java.io.File +import java.time.Duration import java.time.LocalDateTime import java.time.format.DateTimeFormatter fun main() { val dtf = DateTimeFormatter.ISO_DATE_TIME - val db = System.getenv("dbpath") + val db = System.getenv("db_path") ?: throw IllegalArgumentException("Please define an env dbpath, e.g. /data/filemure.db") + val sessionExpiry = System.getenv("session_expiry_sec")?.toInt() ?: (Duration.ofMinutes(30).toSeconds().toInt()) + val app = FilemureApp(SqliteRepository("jdbc:sqlite:$db")) Javalin @@ -35,7 +38,7 @@ fun main() { config.useVirtualThreads = true config.jetty.modifyServletContextHandler { - it.sessionHandler = fileSessionHandler() + it.sessionHandler = fileSessionHandler(sessionExpiry) } } .also { @@ -44,14 +47,14 @@ fun main() { .start(7070) } -fun fileSessionHandler() = SessionHandler().apply { +fun fileSessionHandler(expirySec: Int) = SessionHandler().apply { sessionCache = DefaultSessionCache(this).apply { sessionDataStore = FileSessionDataStore().apply { val baseDir = File(System.getProperty("java.io.tmpdir")) this.storeDir = File(baseDir, "javalin-session").apply { mkdirs() } } } - maxInactiveInterval = 30 * 60 + maxInactiveInterval = expirySec httpOnly = true isSecureRequestOnly = true sameSite = HttpCookie.SameSite.STRICT