happyx icon indicating copy to clipboard operation
happyx copied to clipboard

Server-Sent Event (SSE) not working on Safari

Open jerrygzy opened this issue 11 months ago • 3 comments

hi, been trying the v4.7.4 , I am getting a error

u.local/:1 EventSource's response has a MIME type ("text/plain") that is not "text/event-stream". Aborting the connection.

Screenshot From 2025-01-27 20-47-38

index.html

<!DOCTYPE html>
<head>
  <script src="https://unpkg.com/[email protected]"></script>
  <script src="https://unpkg.com/[email protected]/sse.js"></script>
  <script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-50 min-h-screen p-8 text-center">
  <!-- Current Time by SSE -->
  <div id="current-time"
        class="message time-event"
        hx-ext="sse"
        sse-connect="/events"
        sse-swap="time">
      Waiting for time update...
  </div>
</body>

main.nim


  sse "/events":
    while true:
      let now = now().utc.format("ddd, d MMM yyyy HH:mm:ss")
      await req.sseSend("time", now)
      await sleepAsync(2500)

jerrygzy avatar Jan 27 '25 12:01 jerrygzy

@jerrygzy How you run server? which command you use? because i run this and it works (same happyx version, nim 2.0.8)

Ethosa avatar Jan 29 '25 06:01 Ethosa

@Ethosa sorry for the late reply, been taking a long holiday : )

now I have retested the code. it's working now.

main.nim

# Import HappyX
import
  happyx

# Serve at http://127.0.0.1:5000
serve "127.0.0.1", 5000:
  # on GET HTTP method at http://127.0.0.1:5000/
  get "/":
    # Return plain text
    return FileResponse("./public" / "index.html")
  # on any HTTP method at http://127.0.0.1:5000/public/path/to/file.ext
  staticDir "public"

  sse "/events":
    while true:
      let now = now().utc.format("ddd, d MMM yyyy HH:mm:ss")
      await req.sseSend("time", now)
      await sleepAsync(500)

Image

jerrygzy avatar Feb 23 '25 18:02 jerrygzy

I think there is still a issue with safari which affect chrome on iOS, and safari on MacOS.

it may not a big problem for Desktop Browser User, but we might need to inform users of happyX.

jerrygzy avatar Mar 02 '25 14:03 jerrygzy