Assets with my own plug aren't getting found

I’m using Plug.Static and not using npm.

My Endpoint:

defmodule MyAppWeb.Endpoint do
  use Phoenix.Endpoint, otp_app: :my_app
  socket "/socket", MyAppWeb.UserSocket
  plug MyAppWeb.MyFileUpload

And my plug:

# my_file_upload.ex

defmodule MyAppWeb.FileUploadServant do
  use Plug.Builder

  plug Plug.Static, at: "/uploads", from: "/opt/my_app/uploads"
  plug Plug.Static, at: "", from: "priv/assets/static", gzip: false

  def not_found(conn, _) do
    send_resp(conn, 404, "not found")
  end
end

After deploying on a server and manually copying static assets to “/home/my_user/my_app/builds/priv/assets/static”, it still can’t find them.

      <html>
         <!-- ....... -->
         <link href="/css/my_css_file.css" ...... <--- won't be found

Whereas all “uploads” are found and displayed properly.

What’s up with that?

It looks like the function that handles processing the path ignores "". Maybe try using "*" instead.

Edit: or maybe no "at" option at all, i.e:

  plug Plug.Static, from: "priv/assets/static", gzip: false
2 Likes