commit d92208611f2cc000e6eb0bc7eb7294ba36e80096
parent 4482f8d42bab26a787e154a3466be03d5d51d3b5
Author: ms <ms@taler.net>
Date: Sun, 19 Dec 2021 08:48:13 +0100
serve SPA
Diffstat:
3 files changed, 22 insertions(+), 14 deletions(-)
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -73,6 +73,7 @@ import org.slf4j.LoggerFactory
import org.w3c.dom.Document
import startServer
import tech.libeufin.util.*
+import java.io.IOException
import java.math.BigDecimal
import java.net.BindException
import java.net.URL
@@ -937,7 +938,7 @@ val sandboxApp: Application.() -> Unit = {
// debt limit and possibly other configuration
// (could also be a CLI command for now)
post("/demobanks") {
- throw NotImplementedError("Only available in the CLI.")
+ throw NotImplementedError("Only available in the Sandbox CLI.")
}
get("/demobanks") {
@@ -953,6 +954,26 @@ val sandboxApp: Application.() -> Unit = {
}
get("/demobanks/{demobankid}") {
+ /**
+ * Respond the SPA if the content type is not "application/json".
+ */
+ if (call.request.headers["Content-Type"] != "application/json") {
+ val spa = ClassLoader.getSystemClassLoader().getResourceAsStream("static/spa.html")
+ if (spa == null) throw internalServerError("SPA not found!")
+ call.respondBytesWriter(contentType = ContentType.Text.Html) {
+ writeWhile {
+ val content = try {
+ spa.read()
+ } catch (e: IOException) {
+ throw internalServerError("Could not load the SPA")
+ }
+ if (content == -1) return@writeWhile false
+ it.put(content.toByte())
+ true
+ }
+ }
+ return@get
+ }
expectAdmin(call.request.basicAuth())
val demobankId = call.getUriComponent("demobankid")
val ret: DemobankConfigEntity = transaction {
diff --git a/sandbox/src/main/resources/static/hello.html b/sandbox/src/main/resources/static/hello.html
@@ -1,10 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-<head>
- <meta charset="UTF-8">
- <title>Hello</title>
-</head>
-<body>
-Testing the static folder.
-</body>
-</html>
-\ No newline at end of file
diff --git a/sandbox/src/main/resources/templates/hello.html b/sandbox/src/main/resources/templates/hello.html
@@ -1 +0,0 @@
-Hello, I'm a Jinja '{{ token }}' page!
-\ No newline at end of file