Server-Sent Event (SSE) not working on Safari
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.
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 How you run server? which command you use? because i run this and it works (same happyx version, nim 2.0.8)
@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)
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.