From 0467347f458e3a93237946d4af319a4dbc17b9de Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Fri, 15 Sep 2017 11:30:49 -0500 Subject: [PATCH] Add Serve Static Assets From Custom Directory as a phoenix til --- README.md | 3 ++- ...rve-static-assets-from-custom-directory.md | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 phoenix/serve-static-assets-from-custom-directory.md diff --git a/README.md b/README.md index 7f36783..8439eb6 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/). For a steady stream of TILs from a variety of rocketeers, checkout [til.hashrocket.com](https://til.hashrocket.com/). -_558 TILs and counting..._ +_559 TILs and counting..._ --- @@ -253,6 +253,7 @@ _558 TILs and counting..._ - [Bypass Template Rendering](phoenix/bypass-template-rendering.md) - [Check The Installed Version](phoenix/check-the-installed-version.md) - [Render A Template To A String](phoenix/render-a-template-to-a-string.md) +- [Serve Static Assets From Custom Directory](phoenix/serve-static-assets-from-custom-directory.md) - [Specifying The Digest Directory](phoenix/specifying-the-digest-directory.md) - [Specifying The Server Port](phoenix/specifying-the-server-port.md) diff --git a/phoenix/serve-static-assets-from-custom-directory.md b/phoenix/serve-static-assets-from-custom-directory.md new file mode 100644 index 0000000..7033437 --- /dev/null +++ b/phoenix/serve-static-assets-from-custom-directory.md @@ -0,0 +1,27 @@ +# Serve Static Assets From Custom 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. + +```elixir + plug Plug.Static, + at: "/", from: :my_app, gzip: false, + only: ~w(css fonts images js favicon.ico robots.txt) +``` + +The `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 `priv/static` directory. + +If you instead want to serve your files from a different, custom directory, +you can replace it with the path to that directory. + +```elixir + plug Plug.Static, + at: "/", from: "priv/my_frontend/static", gzip: false, + only: ~w(css fonts images js favicon.ico robots.txt) +``` + +[source](https://hexdocs.pm/plug/Plug.Static.html)