2022-01-25 10:46:25 +01:00
|
|
|
defmodule HAHandler.Web.Router do
|
|
|
|
@moduledoc """
|
|
|
|
This module dispatch incoming HTTP requests to their
|
|
|
|
related logic. Please refer to [1] for details.
|
|
|
|
|
|
|
|
[1] https://hexdocs.pm/plug/Plug.Router.html#content
|
|
|
|
"""
|
|
|
|
|
|
|
|
use Plug.Router
|
|
|
|
|
2022-02-18 17:52:38 +01:00
|
|
|
import HAHandler, only: [acme_challenge_path: 0, static_path: 0]
|
2022-01-25 10:46:25 +01:00
|
|
|
|
|
|
|
alias HAHandler.Web.Controller
|
|
|
|
|
|
|
|
# Note for plugs: oder is important, as a plug may stop
|
|
|
|
# want to stop the pipeline!
|
|
|
|
|
|
|
|
plug Plug.Logger, log: :debug
|
|
|
|
# Note: `plug` is a macro, hence evaluated at
|
|
|
|
# compile-time. The configuration (which path to
|
|
|
|
# serve) cannot be modified at runtime with this
|
|
|
|
# system.
|
|
|
|
plug Plug.Static,
|
|
|
|
at: "/.well-known/acme-challenge/",
|
|
|
|
from: acme_challenge_path()
|
|
|
|
|
2022-02-18 17:52:38 +01:00
|
|
|
plug Plug.Static,
|
|
|
|
at: "/static",
|
|
|
|
from: static_path()
|
|
|
|
|
2022-01-25 10:46:25 +01:00
|
|
|
plug :match
|
|
|
|
plug :dispatch
|
|
|
|
|
|
|
|
get "/", do: Controller.index(conn)
|
|
|
|
|
|
|
|
match _ do
|
|
|
|
send_resp(conn, 404, "Not found")
|
|
|
|
end
|
|
|
|
end
|