plug_static_index_html v1.0.0 Plug.Static.IndexHtml View Source

Serves index.html pages for requests to paths without a filename in Plug applications.

Link to this section Summary

Functions

Invokes the plug, adding default_file to request_path and path_info for directory paths

Initialize plug options

Link to this section Functions

Invokes the plug, adding default_file to request_path and path_info for directory paths

Example

iex> opts = Plug.Static.IndexHtml.init(at: "/doc")
iex> conn = %Plug.Conn{request_path: "/doc/a/", path_info: ["doc", "a"]}
iex> Plug.Static.IndexHtml.call(conn, opts) |> Map.take([:request_path, :path_info])
%{path_info: ["doc", "a", "index.html"], request_path: "/doc/a/index.html"}

Initialize plug options

  • at: The request path to reach for static assets, defaults to “/“
  • default_file: Filename to serve when request path is a directory, defaults to “index.html”

Example

iex> Plug.Static.IndexHtml.init(at: "/doc")
[matcher: ~r|^/doc/(.*/)?$|, default_file: "index.html"]