PhoenixDatastar.StreamPlug (PhoenixDatastar v0.1.14)

Copy Markdown View Source

Global stream endpoint for Datastar live sessions.

Handles GET /__datastar/stream?token=... requests. Verifies the stream token (using Phoenix.Token-based signing), subscribes to the session's GenServer, and enters the SSE loop (PhoenixDatastar.Server.enter_loop/2).

Returns 401 if the token is missing or invalid. Returns 409 if the GenServer is no longer running (e.g., session expired), signaling the client to reload.

Expected route

get "/__datastar/stream", PhoenixDatastar.StreamPlug, :stream