I'm trying to do [server-sent 
events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)
 in Jester.

What I have now is this: 
    
    
    router index:
      get "/time":
        let data =
          "retry: 3000\n" &
          "data: {time: \'" & getClockStr() & "\'} \n\n"
        resp(data, "text/event-stream")
    
    
    Run

It's working because browser is reconnecting every 3 seconds and getting new 
data.  
But in principle, the server is supposed to keep the existing connection open 
and send more data through it.  


I've found some code that does exactly what I want in 
[alltest.nim](https://github.com/dom96/jester/blob/5a54b5e2cc0b6b7405536fdd79b65aa133cac6c8/tests/alltest.nim#L79),
 but the `response` is undeclared in this context. 
    
    
    # get "/live":
    #   await response.sendHeaders()
    #   for i in 0 .. 10:
    #     await response.send("The number is: " & $i & "</br>")
    #     await sleepAsync(1000)
    #   response.client.close()
    
    
    Run

Is there any way to get `response` object inside `route`? Or is there another 
approach?

Reply via email to