simple-web-app

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit c6c96d2d8b32daa1e36c9b787f85b50bd166c751
parent 492f110322442a94b16500601576bd274ded2fcf
Author: Silas Brack <silasbrack@gmail.com>
Date:   Mon,  8 Jun 2026 17:50:34 +0200

feat: add realtime comments via SSE subscription

Subscribe to trailbase's table-level SSE endpoint for comments.
When a new comment is inserted for the current story, reload the
page to show it. Nginx configured with proxy_buffering off for SSE.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

Diffstat:
Mtemplates/story.html | 18+++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/templates/story.html b/templates/story.html @@ -82,7 +82,23 @@ <p class="login-prompt"><a href="/login">Log in</a> to comment.</p> {% endif %} - <section class="comments"> + <section class="comments" id="comments-section"> {% include "comments.html" %} </section> + + <script> + (function() { + var storyId = {{ story.id }}; + var evtSource = new EventSource('/api/records/v1/comment/subscribe/*'); + evtSource.onmessage = function(event) { + try { + var data = JSON.parse(event.data); + // Only reload if the comment is for this story + if (data.Insert && data.Insert.story_id === storyId) { + window.location.reload(); + } + } catch(e) {} + }; + })(); + </script> </div>