DurableDashboard.Router (DurableDashboard v0.1.0-rc)

Copy Markdown View Source

Router macro for embedding the Durable dashboard into a host Phoenix application.

Why a macro

The dashboard's LiveViews can't be mounted via forward because Phoenix LiveView's session validation uses the host endpoint's router for route lookup — routes inside a forwarded sub-router fail the live_session check with unauthorized live_redirect. The macro emits the routes inline in the host's router, so session.router matches the URL and the validation passes.

Same approach phoenix_live_dashboard uses for live_dashboard/2.

Usage

One line. Add this at the top level of your router (not inside a scope or pipe_through block — the macro defines its own pipelines):

defmodule MyAppWeb.Router do
  use MyAppWeb, :router

  # Your existing pipelines + scopes...

  use DurableDashboard.Router, mount: "/dashboard", durable: MyApp.Durable
end

Or equivalently, if you prefer the explicit form:

import DurableDashboard.Router
dashboard_routes "/dashboard", durable: MyApp.Durable

This emits two pipelines (:durable_dashboard_browser and :durable_dashboard_assets) and two scopes:

  • GET /dashboard (Overview)
  • GET /dashboard/workflows (list of workflow definitions)
  • GET /dashboard/workflows/:name (executions for that workflow)
  • GET /dashboard/executions (global executions list)
  • GET /dashboard/executions/:id[/:tab] (single execution detail)
  • GET /dashboard/inputs
  • GET /dashboard/schedules
  • GET /dashboard/settings
  • GET /dashboard/__assets__/* (CSS/JS/font assets — no CSRF, since cross-origin module-script loading is normal and the assets are public-by-design)

Options

  • :durable — Durable instance name (default: Durable)
  • :live_socket_path — path the host configured for Phoenix.LiveView.Socket (default: "/live")
  • :on_mount — list of on_mount hooks the host wants to inject for auth/etc (default: [])

Summary

Functions

One-line use form. Equivalent to import + dashboard_routes/2.

Embeds the dashboard's routes at prefix in the calling router.

Functions

__using__(opts)

(macro)

One-line use form. Equivalent to import + dashboard_routes/2.

Required option: :mount — the URL prefix the dashboard mounts at. Other options pass straight through to dashboard_routes/2.

Example

use DurableDashboard.Router, mount: "/dashboard", durable: MyApp.Durable

dashboard_routes(prefix, opts \\ [])

(macro)

Embeds the dashboard's routes at prefix in the calling router.