How do I add new folders to static_paths() in phoenix 17.11?

I have images in priv/static/uploads directory but they are not showing. I inspected static_paths IO.inspect(BlogWeb.static_paths, label: "Static Paths") and found out that uploads folder is not there: Static Paths: ["assets", "fonts", "images", "favicon.ico", "robots.txt"]. Is there a way I could add the uploads directory to the static_paths plug?

 plug Plug.Static,
    at: "/",
    from: :blog_web,
    gzip: false,
    only: BlogWeb.static_paths()

I tried this:

plug Plug.Static,
    at: "/",
    from: :blog_web,
    gzip: false,
    only:  ~w(css fonts images js favicon.ico robots.txt uploads)

The images are rendering but it seems that it interferes with CSS.

The default is:

  def static_paths, do: ~w(assets fonts images favicon.ico robots.txt)

And you would find your CSS at assets/css, did you try removing css and js from your config and replacing it with assets? Then add uploads as you did in your second example.

1 Like

BlogWeb.static_paths is in your project in lib/blog_web.ex. You need to modify that function with your new paths rather than hardcoding them into Endpoint as it is used in a couple of different places.

Thank you so much. This worked

1 Like