Monitorex. Router
(monitorex v0.8.0)
Copy Markdown
Router macros for embedding the Monitorex dashboard in your Phoenix application.
Usage
defmodule MyAppWeb.Router do
use Phoenix.Router
import Monitorex.Router
scope "/monitorex" do
http_dashboard []
end
endThe pipeline that runs the dashboard routes must include
:protect_from_forgery (or Plug.CSRFProtection). The dashboard layout
reads the CSRF token to authenticate the LiveView socket connection, and the
LiveView client sends it back as _csrf_token.
Summary
Functions
Defines the Monitorex HTTP dashboard routes.
Functions
Defines the Monitorex HTTP dashboard routes.
Options
:live_view— module to use as the dashboard LiveView (default:Monitorex.DashboardLive):layout— root layout module (default:{Monitorex.Layouts, :root}):assets_path— asset mount path (default:"/dashboard-assets"):socket_path— LiveSocket path of the host application'sPhoenix.LiveView.Socketendpoint (default:"/live"):on_mount— additional on_mount hooks. The default is[Monitorex.Authentication, Monitorex.MountOptions]. If you override this option you must include bothMonitorex.Authentication(auth) andMonitorex.MountOptions(which assigns the mount prefix, assets path and socket path to the socket for the root layout); omittingMonitorex.MountOptionsleaves the layout with its default unprefixed hrefs and/livesocket path.:api_path— API mount path (default:"/api"). Set tonilorfalseto disable the REST API entirely.
Example
http_dashboard live_view: MyApp.CustomLiveThis generates:
live_session :monitorex_dashboard,
root_layout: {Monitorex.Layouts, :root},
on_mount: [Monitorex.Authentication, Monitorex.MountOptions],
session: {Monitorex.MountOptions, :session, ["/dashboard-assets", "/live"]} do
get "/dashboard-assets/*path", Monitorex.Assets, :call
live "/", Monitorex.DashboardLive, :index
live "/:page", Monitorex.DashboardLive, :index
live "/:page/:host", Monitorex.DashboardLive, :index
end
# API routes (outside live_session, no auth)
forward "/api", Monitorex.ApiPlug