defmodule ApiPlayground do @moduledoc """ Documentation for ApiPlayground. """ def init(opts), do: opts def call(conn, opts) do routes = Keyword.get(opts, :routes) conn |> Plug.Conn.assign(:routes, routes) |> Plug.Conn.assign(:conn, conn) |> ApiPlayground.Router.call(opts) end end defmodule ApiPlayground.Router do use Plug.Router plug Plug.Static, at: "/", from: {:api_playground, "priv/static"} plug :match plug :dispatch get "/" do send_resp(conn, 200, ApiPlayground.View.render(conn.assigns)) end end defmodule ApiPlayground.View do require EEx EEx.function_from_file :def, :render, "lib/templates/index.html.eex", [:assigns] def static_path(conn, file) do conn.request_path <> file end end