add a simple browser based demo

Signed-off-by: hrj <harshad.rj@gmail.com>
This commit is contained in:
hrj
2021-04-19 13:14:36 +05:30
parent f38d6ee191
commit 6189ffce89
3 changed files with 82 additions and 2 deletions

View File

@@ -7,6 +7,8 @@ import lc.core.{Parameters, Id, Answer, Error, ByteConvert}
import lc.core.Config.formats
import org.limium.picoserve
import org.limium.picoserve.Server.ByteResponse
import scala.io.Source
import org.limium.picoserve.Server.StringResponse
class Server(port: Int) {
val server: picoserve.Server = picoserve.Server.builder()
@@ -35,6 +37,11 @@ class Server(port: Int) {
val result = Captcha.checkAnswer(answer)
getResponse(result)
})
.GET("/demo/index.html", (_) => {
val resStream = getClass().getResourceAsStream("/index.html")
val str = Source.fromInputStream(resStream).mkString
new StringResponse(200, str)
})
.build()
private def getResponse(response: Either[Error, ByteConvert]): ByteResponse = {