Description
SSE example not working on live
I'm working on my localhost, everything is fine, but I'm broadcasting on the live server SSE is not working. Does anyone have any suggestions for checkpoints.
I see on server logs ------00a0*0** lines.
I used nginx to my server.
func GETAssetSSE(c *gin.Context) {
v, ok := c.Get("clientChan")
if !ok {
fmt.Println("clientChan not found 1")
return
}
clientChan, ok := v.(dbconfig.ClientChan)
if !ok {
fmt.Println("clientChan not found 2")
return
}
c.Stream(func(w io.Writer) bool {
// Stream message to client from message channel
if msg, ok := <-clientChan; ok {
fmt.Println("msg", msg)
c.SSEvent("message", msg)
fmt.Println("------0**0*a0*0*********")
fmt.Println("------0**0*a0*0*********")
fmt.Println("------0**0*a0*0*********")
fmt.Println("------0**0*a0*0*********")
fmt.Println("------0**0*a0*0*********")
fmt.Println("------0**0*a0*0*********")
fmt.Println("------0**0*a0*0*********")
fmt.Println("------0**0*a0*0*********")
return true
}
return false
})
}
Environment
- go version: go1.19.10
- gin version (or commit ref): v1.9.1
- operating system: ubuntu
Comment From: icobani
Done :)))))
func HeadersMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
c.Writer.Header().Set("Content-Type", "text/event-stream")
c.Writer.Header().Set("Cache-Control", "no-cache")
c.Writer.Header().Set("Connection", "keep-alive")
//c.Writer.Header().Set("Transfer-Encoding", "chunked")
c.Writer.Header().Set("X-Accel-Buffering", "no")
c.Next()
}
}