Dstar.Page.Plug (dstar v0.3.0)

Copy Markdown View Source

The plug behind Dstar.Router.dstar/2. Drives Dstar.Page callbacks:

  • {:page, Module} — GET: mount/2 then render/1 through Phoenix's view pipeline (root layout, flash, page_title all apply).
  • {:event, Module} — POST _event/:event: reads signals, optional authorize/2, starts SSE, calls handle_event/3.
  • {:stream, Module} — POST: optional authorize/2, atomically claims dedup ownership when stream_key/1 is defined, starts SSE, calls handle_connect/2, then runs the receive loop on Dstar.Stream, dispatching to handle_info/2. A keyed claim failure returns 503 before the callback.

authorize/2 is the pre-SSE seam: a halted or already-staged response is returned as ordinary HTTP and SSE never starts. Before authorization, signals are fetched with the page's :max_signal_bytes limit; malformed/non-object payloads return 400 and oversized payloads return 413. mount/2 does not run on event or stream POSTs.

All control flow lives here as plain functions — pages contain only callbacks.