I configure Plug.Static to:
plug Plug.Static,
at: "/admin",
and point the assets to it:
<link phx-track-static rel="stylesheet" href={~p"/admin/assets/app.css"} />
This serves the web page correctly, but I am warned against it:
warning: no route path for MyWeb.Router matches "/admin/assets/app.css"
lib/my_web/components/layouts/root.html.heex:10: MyWeb.Layouts.root/1
CI won’t let warnings through, so…
Attempt 1
I tried working with the endpoint :static_url
config, but could not figure out a way to make this config help. In fact, I’m not sure how this would be used now that we have verified routes? Is this route helper specific?
config :my_web, MyWeb.Endpoint
static_url: [path: "/admin"]
Attempt 2
I reset the at:
to root
plug Plug.Static,
at: "/",
and changed static_paths/0
to hold the prefix
def static_paths, do: ~w(assets fonts images favicon.ico robots.txt) |> Enum.map(&Path.join("admin", &1))
but this returned 404s for app.css
Workable Solution
I was able to solve the warnings with the below
use Phoenix.VerifiedRoutes,
endpoint: MyWeb.Endpoint,
router: MyWeb.Router,
statics: Enum.map(MyWeb.static_paths(), &Path.join("admin", &1))
but it didn’t quite feel ideal. I’m wondering if there’s something more direct that I’m missing.