aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarvin Borner2019-04-02 17:48:23 +0200
committerMarvin Borner2019-04-02 17:48:23 +0200
commit0742b3437ec57b13b11b606d0657f5e886e58d94 (patch)
tree6fe57626dfc7c5008149562a9a221a8e313cf6cb /src
Initial project layout
Diffstat (limited to 'src')
-rw-r--r--src/main/kotlin/App.kt26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/main/kotlin/App.kt b/src/main/kotlin/App.kt
new file mode 100644
index 0000000..2da5ced
--- /dev/null
+++ b/src/main/kotlin/App.kt
@@ -0,0 +1,26 @@
+package space.anity
+
+import io.javalin.Javalin
+import java.io.File
+import java.nio.file.Files
+import java.nio.file.Paths
+
+fun main(args: Array<String>) {
+ val app = Javalin.create().start(7000)
+ val fileHome = "files"
+
+ app.get("/") { ctx ->
+ ctx.result("Hello World")
+ }
+
+ app.get("/files/*") { ctx ->
+ var files = ""
+ Files.list(Paths.get("$fileHome${ctx.splats()[0]}/")).forEach {
+ val fileName = it.toString().drop(fileHome.length + (if (ctx.splats()[0].isNotEmpty()) ctx.splats()[0].length + 1 else 0))
+ val filePath = "$fileHome${it.toString().drop(fileHome.length)}"
+ files += if (File("$fileHome${it.toString().drop(fileHome.length)}").isDirectory) "$fileName/\n" else "$fileName\n"
+ }
+ ctx.result(files)
+ //File("test").writeText(ctx.splat(0)!!)
+ }
+}