jerdew
Serving from a different Plug.Static `at:` emits verified routes warnings for assets
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.
Marked As Solved
LostKobrakai
The :statics setting of Phoenix.VerifiedRoutes expects a list of top level folder or filenames (similar to the Plug.Static :only setting). It does not take full paths. In your case that would just be ["admin"] if everything is within that folder.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









