WIP
This commit is contained in:
parent
33204f1dde
commit
879568cd04
1 changed files with 29 additions and 14 deletions
|
|
@ -1,24 +1,39 @@
|
||||||
import asynchttpserver, asyncdispatch
|
import asynchttpserver, asyncdispatch, httpclient
|
||||||
import osproc, strutils, parseopt
|
import osproc, strutils, parseopt
|
||||||
|
|
||||||
proc getContent(pad:string):string =
|
proc getContent(pad:string):string =
|
||||||
discard
|
discard
|
||||||
|
|
||||||
proc requestHandler(req:Request) {.async.} =
|
proc requestHandler(req:Request) {.async.} =
|
||||||
if req.url.path.startsWith("/compile"):
|
let
|
||||||
let
|
padName = req.url.path
|
||||||
padName = req.url.path
|
content = getContent(padName)
|
||||||
content = getContent(padName)
|
let (output, exitCode) = execCmdEx("make")
|
||||||
let (output, exitCode) = execCmdEx("make")
|
let headers = if exitCode == 0: newHttpHeaders([("Content-Type","application/pdf")])
|
||||||
let headers = if exitCode == 0: newHttpHeaders([("Content-Type","application/pdf")])
|
else: newHttpHeaders([("Content-Type","text/plain")])
|
||||||
else: newHttpHeaders([("Content-Type","text/plain")])
|
let pdf = if exitCode == 0: readFile("Abgabe.pdf")
|
||||||
let pdf = if exitCode == 0: readFile("Abgabe.pdf")
|
else: output
|
||||||
else: output
|
await req.respond(Http200, pdf, headers)
|
||||||
await req.respond(Http200, pdf, headers)
|
|
||||||
else:
|
|
||||||
await req.respond(Http404, "Not a valid API call")
|
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
var
|
var
|
||||||
|
p = initOptParser()
|
||||||
|
port = 8080
|
||||||
|
etherpadAddress = "http://localhost:9001/"
|
||||||
server = newAsyncHttpServer()
|
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