2022-01-25 10:46:25 +01:00
|
|
|
defmodule HAHandler.Web.Router do
|
2022-02-23 17:53:00 +01:00
|
|
|
@moduledoc """
|
|
|
|
This module dispatch incoming HTTP requests to their
|
|
|
|
related logic. Please refer to [1] for details.
|
2022-01-25 10:46:25 +01:00
|
|
|
|
2022-02-23 17:53:00 +01:00
|
|
|
[1] https://hexdocs.pm/plug/Plug.Router.html#content
|
|
|
|
"""
|
2022-01-25 10:46:25 +01:00
|
|
|
|
2022-02-23 17:53:00 +01:00
|
|
|
use Plug.Router
|
2022-01-25 10:46:25 +01:00
|
|
|
|
2022-02-23 17:53:00 +01:00
|
|
|
alias HAHandler.Web.Controller
|
2022-01-25 10:46:25 +01:00
|
|
|
|
2022-02-23 17:53:00 +01:00
|
|
|
# Note for plugs: oder is important, as a plug may stop
|
|
|
|
# want to stop the pipeline!
|
2022-01-25 10:46:25 +01:00
|
|
|
|
2022-02-23 17:53:00 +01:00
|
|
|
plug(Plug.Logger, log: :debug)
|
2022-02-19 11:39:04 +01:00
|
|
|
|
2022-02-23 17:53:00 +01:00
|
|
|
# We use replug to allow for runtime configuration in release (as macros such
|
|
|
|
# as the `plug` call ae evaluated are compile-time).
|
|
|
|
plug(Replug,
|
|
|
|
plug: Plug.Static,
|
|
|
|
opts: {HAHandler, :acme_challenges_static_config}
|
|
|
|
)
|
2022-02-18 17:52:38 +01:00
|
|
|
|
2022-02-23 17:53:00 +01:00
|
|
|
plug(Replug,
|
|
|
|
plug: Plug.Static,
|
|
|
|
opts: {HAHandler, :assets_static_config}
|
|
|
|
)
|
2022-01-25 10:46:25 +01:00
|
|
|
|
2022-02-23 17:53:00 +01:00
|
|
|
plug(:match)
|
|
|
|
plug(:dispatch)
|
2022-01-25 10:46:25 +01:00
|
|
|
|
2022-02-23 17:53:00 +01:00
|
|
|
get("/", do: Controller.index(conn))
|
|
|
|
|
|
|
|
match _ do
|
|
|
|
send_resp(conn, 404, "Not found")
|
|
|
|
end
|
2022-01-25 10:46:25 +01:00
|
|
|
end
|