Skip to content

Instantly share code, notes, and snippets.

@runvnc
Created March 16, 2014 04:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save runvnc/9578737 to your computer and use it in GitHub Desktop.
Save runvnc/9578737 to your computer and use it in GitHub Desktop.
Using ttyl and finished
import jester, strtabs, htmlgen, sockets, strutils, tables, oids, cgi, msgqredis, marshal, hashes, os, oicconf, oicutils
var myrespq = ""
type
TResponseObjects = TTable[string, PResponse]
var responseObjects: TResponseObjects = initTable[string, PResponse]()
proc uniqidstr():string =
var sid:string = $(genOid())
sid.delete(sid.len-2, sid.len-1)
return sid
proc newMessage(queue:string, msg:seq[string]) =
var responseData = to[TResponseObject](msg[1])
var response = responseObjects[responseData.requestId]
if response != nil and responseData.body != "{{END}}":
resp responseData.body
else:
var dummy = 2
if responseData.body == "{{END}}":
finished
myrespq = uniqidstr()
msgqredis.init(newMessage, myrespq)
proc queueRequest(request:TRequest, response: PResponse) =
# get unique id for this request
var reqid = uniqidstr()
for key, val in request.params:
echo key & ": " & val
var req = TQueuedRequest(responseQueue: myrespq, requestId: reqid,
path:request.pathInfo, query: $request.params)
# push request data with unique id and list I am listening on
responseObjects[reqid] = response
var len = pushMessage("http", $$req)
proc quitIt() {.noconv.} =
echo "Cleaning up.."
close()
echo "Server shutdown and socket closed."
addQuitProc(quitIt)
get "/proc":
queueRequest(request, response)
ttyl
run("", TPort(3004))
echox("Server running on port 3004" )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment