Files
something-erlang/lib/something_erlang_web/router.ex

75 lines
2.1 KiB
Elixir
Raw Normal View History

2022-05-23 15:57:15 +02:00
defmodule SomethingErlangWeb.Router do
use SomethingErlangWeb, :router
import SomethingErlangWeb.UserAuth
2022-05-23 15:57:15 +02:00
pipeline :browser do
plug(:accepts, ["html"])
plug(:fetch_session)
plug(:fetch_live_flash)
plug(:put_root_layout, html: {SomethingErlangWeb.Layouts, :root})
plug(:protect_from_forgery)
plug(:put_secure_browser_headers)
plug(:fetch_current_user)
plug(:load_bbcookie)
2022-05-23 15:57:15 +02:00
end
pipeline :api do
plug(:accepts, ["json"])
end
scope "/", SomethingErlangWeb do
pipe_through(:browser)
get("/", PageController, :home)
post("/", PageController, :to_forum_path)
live_session :user_browsing,
on_mount: [{SomethingErlangWeb.UserAuth, :ensure_authenticated}] do
live("/thread", ThreadLive)
live("/thread/:id", ThreadLive)
end
end
## Authentication routes
scope "/", SomethingErlangWeb do
pipe_through([:browser, :redirect_if_user_is_authenticated])
live_session :redirect_if_user_is_authenticated,
on_mount: [{SomethingErlangWeb.UserAuth, :redirect_if_user_is_authenticated}] do
live("/users/log_in", UserLoginLive, :new)
end
post("/users/log_in", UserSessionController, :create)
2022-05-23 15:57:15 +02:00
end
scope "/", SomethingErlangWeb do
pipe_through([:browser])
2022-05-23 15:57:15 +02:00
delete("/users/log_out", UserSessionController, :delete)
2022-05-23 15:57:15 +02:00
end
2024-06-02 13:31:19 +02:00
# Other scopes may use custom stacks.
# scope "/api", SomethingErlangWeb do
# pipe_through :api
# end
2022-05-23 15:57:15 +02:00
2024-03-29 15:54:42 +01:00
# Enable LiveDashboard and Swoosh mailbox preview in development
if Application.compile_env(:something_erlang, :dev_routes) do
# If you want to use the LiveDashboard in production, you should put
# it behind authentication and allow only admins to access it.
# If your application does not have an admins-only section yet,
# you can use Plug.BasicAuth to set up some basic authentication
# as long as you are also using SSL (which you should anyway).
import Phoenix.LiveDashboard.Router
2022-05-23 15:57:15 +02:00
2024-03-29 15:54:42 +01:00
scope "/dev" do
pipe_through(:browser)
2023-01-18 16:13:51 +01:00
live_dashboard("/dashboard", metrics: SomethingErlangWeb.Telemetry)
forward("/mailbox", Plug.Swoosh.MailboxPreview)
2023-01-18 16:13:51 +01:00
end
2022-05-23 15:57:15 +02:00
end
end