diff --git a/tests/index_sse.html b/tests/index_sse.html new file mode 100644 index 00000000..d0169055 --- /dev/null +++ b/tests/index_sse.html @@ -0,0 +1,87 @@ + + + + SSE Demo with HTMX + + + + + +

Server-Sent Events Demo (HTMX)

+ + +
+ Waiting for time update... +
+ + + + + diff --git a/tests/testc21.nim b/tests/testc21.nim index 6470ecd9..c3722f6c 100644 --- a/tests/testc21.nim +++ b/tests/testc21.nim @@ -2,6 +2,13 @@ import ../src/happyx +regCORS: + methods: "*" + origins: "*" + headers: "*" + credentials: true + + serve "127.0.0.1", 5000: get "/": "" @@ -9,5 +16,14 @@ serve "127.0.0.1", 5000: id post "/user": "" + + # Server-sent events + # https://github.com/HapticX/happyx/discussions/365 + sse "/sse": + while true: + let now = now().utc.format("ddd, d MMM yyyy HH:mm:ss") + await req.sseSend("time", now) + await sleepAsync(2500) + notfound: "method not allowed"