WIP
This commit is contained in:
parent
33204f1dde
commit
879568cd04
1 changed files with 29 additions and 14 deletions
|
|
@ -1,11 +1,10 @@
|
|||
import asynchttpserver, asyncdispatch
|
||||
import asynchttpserver, asyncdispatch, httpclient
|
||||
import osproc, strutils, parseopt
|
||||
|
||||
proc getContent(pad:string):string =
|
||||
discard
|
||||
|
||||
proc requestHandler(req:Request) {.async.} =
|
||||
if req.url.path.startsWith("/compile"):
|
||||
let
|
||||
padName = req.url.path
|
||||
content = getContent(padName)
|
||||
|
|
@ -15,10 +14,26 @@ proc requestHandler(req:Request) {.async.} =
|
|||
let pdf = if exitCode == 0: readFile("Abgabe.pdf")
|
||||
else: output
|
||||
await req.respond(Http200, pdf, headers)
|
||||
else:
|
||||
await req.respond(Http404, "Not a valid API call")
|
||||
|
||||
when isMainModule:
|
||||
var
|
||||
p = initOptParser()
|
||||
port = 8080
|
||||
etherpadAddress = "http://localhost:9001/"
|
||||
server = newAsyncHttpServer()
|
||||
waitFor server.serve(Port(8080), requestHandler)
|
||||
|
||||
# Parse command-line args
|
||||
while true:
|
||||
p.next()
|
||||
case p.kind
|
||||
of cmdEnd: break
|
||||
of cmdShortOption, cmdLongOption:
|
||||
case p.key
|
||||
of "p", "port":
|
||||
port = p.val.parseInt
|
||||
of "a", "etherpad-address":
|
||||
etherpadAddress = p.val
|
||||
else: discard
|
||||
of cmdArgument: continue
|
||||
|
||||
waitFor server.serve(Port(port), requestHandler)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue