Framework.OverlayRouter (Framework v0.5.0)

View Source

Route definitions for Framework debug overlay system.

This module provides route definitions that host Phoenix applications can mount to enable the Framework debug overlay at /overlay.

Usage in host application

Add to your Phoenix router:

defmodule MyAppWeb.Router do
  # ... other routes

  scope "/overlay" do
    Framework.OverlayRouter.mount_routes(__MODULE__)
  end
end

This makes the overlay available at /overlay as documented.

Security

The overlay should only be available in development/test environments. Host applications should implement appropriate security checks.

Summary

Functions

Plug function for security checks in host applications.

Mount overlay routes in a Phoenix router.

Get the AST representation of overlay routes for testing.

Functions

ensure_development_only(conn, opts)

Plug function for security checks in host applications.

Host applications should use this plug to ensure overlay is only available in appropriate environments.

Usage in host controller:

defmodule MyAppWeb.OverlayController do
  use MyAppWeb, :controller

  plug :ensure_development_only

  defdelegate index(conn, params), to: Framework.OverlayController
  # ... other overlay actions

  defp ensure_development_only(conn, _opts) do
    if Application.get_env(:my_app, :overlay_enabled, Mix.env() in [:dev, :test]) do
      conn
    else
      conn
      |> put_status(:forbidden)
      |> json(%{error: "Debug overlay is disabled in this environment"})
      |> halt()
    end
  end
end

mount_routes(router_module)

(macro)

Mount overlay routes in a Phoenix router.

Usage in host Phoenix application:

scope "/overlay" do
  Framework.OverlayRouter.mount_routes(__MODULE__)
end

routes()

Get the AST representation of overlay routes for testing.

Returns the quoted route definitions for testing route structure.