Plug.Static
A plug for serving static assets.
It expects two options on initialization:
:at
- the request path to reach for static assets. It must be a binary.:from
- the filesystem path to read static assets from. It must be a binary, containing a file system path, or an atom representing the application name, where assets will be served from the priv/static.
The preferred form is to use :from
with an atom, since
it will make your application independent from the starting
directory.
If a static asset cannot be found, it simply forwards the connection to the rest of the stack.
Options
:gzip
- useFILE.gz
if it exists in the static directory and ifaccept-encoding
is set to allow gzipped content (defaults tofalse
).:cache
- sets cache headers on response (defaults to:true
)
Examples
This filter can be mounted in a Plug.Builder as follow:
defmodule MyPlug do
use Plug.Builder
plug Plug.Static, at: "/public", from: :my_app
plug :not_found
def not_found(conn, _) do
Plug.Conn.send_resp(conn, 404, "not found")
end
end
Summary
call(conn, arg2) |
init(opts) |