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

73 lines
2.0 KiB
Elixir
Raw Normal View History

2022-05-23 15:57:15 +02:00
defmodule SomethingErlangWeb.Router do
use SomethingErlangWeb, :router
import SomethingErlangWeb.UserAuth
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_live_flash
2023-01-18 16:13:51 +01:00
plug :put_root_layout, {SomethingErlangWeb.Layouts, :root}
2022-05-23 15:57:15 +02:00
plug :protect_from_forgery
plug :put_secure_browser_headers
plug :fetch_current_user
2024-03-29 15:54:42 +01:00
plug :load_bbcookie
2022-05-23 15:57:15 +02:00
end
pipeline :api do
plug :accepts, ["json"]
end
scope "/", SomethingErlangWeb do
2023-01-18 16:13:51 +01:00
pipe_through [:browser]
2022-05-23 15:57:15 +02:00
2023-01-18 16:13:51 +01:00
get "/", PageController, :home
2023-02-17 15:05:27 +01:00
post "/", PageController, :to_forum_path
2022-05-23 15:57:15 +02:00
2023-01-18 16:13:51 +01:00
live_session :user_browsing,
2024-03-29 15:54:42 +01:00
on_mount: [{SomethingErlangWeb.UserAuth, :ensure_authenticated}] do
2023-01-18 16:13:51 +01:00
live "/thread", ThreadLive
2023-02-17 15:05:27 +01:00
live "/thread/:id", ThreadLive
2023-01-18 16:13:51 +01:00
end
2022-05-23 15:57:15 +02:00
end
## Authentication routes
scope "/", SomethingErlangWeb do
pipe_through [:browser, :redirect_if_user_is_authenticated]
2023-01-18 16:13:51 +01:00
live_session :redirect_if_user_is_authenticated,
on_mount: [{SomethingErlangWeb.UserAuth, :redirect_if_user_is_authenticated}] do
live "/users/log_in", UserLoginLive, :new
end
2022-05-23 15:57:15 +02:00
post "/users/log_in", UserSessionController, :create
end
scope "/", SomethingErlangWeb do
2024-03-29 15:54:42 +01:00
pipe_through [:browser]
2022-05-23 15:57:15 +02:00
2024-03-29 15:54:42 +01:00
delete "/users/log_out", UserSessionController, :delete
2022-05-23 15:57:15 +02:00
end
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
2024-03-29 15:54:42 +01:00
live_dashboard "/dashboard",
ecto_repos: [SomethingErlang.Repo],
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