34 lines
685 B
Elixir
34 lines
685 B
Elixir
defmodule PreDotDn.DevServer do
|
|
use Plug.Router
|
|
|
|
plug(Plug.Logger)
|
|
plug(:rewrite_dirs)
|
|
plug(Plug.Static, at: "", from: "priv/static")
|
|
|
|
get "/health" do
|
|
conn |> resp(200, "ok") |> halt()
|
|
end
|
|
|
|
plug(:match)
|
|
plug(:dispatch)
|
|
|
|
def rewrite_dirs(conn, _) do
|
|
is_directory =
|
|
case Enum.reverse(conn.path_info) do
|
|
[] ->
|
|
true
|
|
|
|
[last_segment | _] ->
|
|
!String.contains?(last_segment, ".")
|
|
end
|
|
|
|
if is_directory do
|
|
request_path = conn.request_path <> "index.html"
|
|
path_info = conn.path_info ++ ["index.html"]
|
|
|
|
%{conn | path_info: path_info, request_path: request_path}
|
|
else
|
|
conn
|
|
end
|
|
end
|
|
end
|