Serve Static Assets From Custom Phoenix Directory
When you new up a Phoenix project, an
endpoint.ex file will be generated.
This file is full of different plugs for handling incoming traffic. The
Plug.Static declaration specifies how your application will handle and
serve requests for static files.
plug Plug.Static, at: "/", from: :my_app, gzip: false, only: ~w(css fonts images js favicon.ico robots.txt)
from options declares where these static files are located. In this
case it references our application (
:my_app) as the target which will
translate to its
If you instead want to serve your files from a different, custom directory, you can replace it with the path to that directory.
plug Plug.Static, at: "/", from: "priv/my_frontend/static", gzip: false, only: ~w(css fonts images js favicon.ico robots.txt)