DialectoInContext.Plug (dialecto_in_context v0.1.0)

Copy Markdown View Source

The dev server's side of the in-context editor (spec-0017 §1.4). Put it in the endpoint before the router (and before Plug.Parsers, so it reads its own small JSON bodies):

  • GET /__dialecto/context — the site's git context (DialectoInContext.GitContext);
  • POST /__dialecto/overrides — the overlay's saved drafts (DialectoInContext.Overrides), applied by the Gettext wrapper;
  • POST /__dialecto/marking — {on: true|false}: the open editor turns marking on and keeps it on by heartbeat (DialectoInContext.Store);
  • the overlay loader injected before </head> of text/html responses, as Phoenix's live reloader injects its own, so no template changes.

Loopback only: the Host must be localhost, 127.0.0.1 or [::1] (which also defeats DNS rebinding), a POST must carry this site's own Origin, and a request with a foreign Origin or Sec-Fetch-Site: cross-site is refused — the Astro add-on's rules. The loader goes only into top-level documents on a loopback host (an iframe — such as Dialecto's own sidebar — never gets an overlay of its own).