fp/services/bright/lib/bright_web/router.ex

126 lines
3.1 KiB
Elixir

defmodule BrightWeb.Router do
use BrightWeb, :router
pipeline :browser do
plug :accepts, ["html", "json"]
plug :fetch_session
plug :fetch_live_flash
plug :put_root_layout, html: {BrightWeb.Layouts, :root}
plug :protect_from_forgery
plug :put_secure_browser_headers
end
defp fetch_current_user(conn, _) do
if user_uuid = get_session(conn, :current_uuid) do
assign(conn, :current_uuid, user_uuid)
else
new_uuid = Ecto.UUID.generate()
conn
|> assign(:current_uuid, new_uuid)
|> put_session(:current_uuid, new_uuid)
end
end
pipeline :api do
plug :accepts, ["json"]
end
scope "/" do
pipe_through [:browser]
# get "/streams/new", StreamController, :new
# post "/streams", StreamController, :create
end
scope "/", BrightWeb do
pipe_through :browser
get "/", PageController, :home
resources "/products", ProductController
get "/patrons", PatronController, :index
get "/about", PageController, :about
get "/api", PageController, :api
get "/up", PageController, :health
resources "/orders", OrderController, only: [:create, :show]
resources "/archive", StreamController
get "/streams", StreamController, :index
get "/streams/:id", StreamController, :show
get "/streams/new", StreamController, :new
post "/streams", StreamController, :create
resources "/vods", VodController
resources "/vtubers", VtuberController
resources "/vt", VtuberController do
resources "/vods", VodController
end
# resources "/users", UserController
resources "/tags", TagController
## @todo DANGER, platforms must only be writable by admins, (unless we implement SVG sanitizing)
resources "/platforms", PlatformController
live "/thermostat", ThermostatLive
get "/hello", HelloController, :index
get "/hello/:messenger", HelloController, :show
live "/posts", PostLive.Index, :index
live "/posts/new", PostLive.Index, :new
live "/posts/:id/edit", PostLive.Index, :edit
live "/posts/:id", PostLive.Show, :show
live "/posts/:id/show/edit", PostLive.Show, :edit
end
# Other scopes may use custom stacks.
scope "/api", BrightWeb do
pipe_through :api
resources "/urls", UrlController, except: [:new, :edit]
end
# Enable LiveDashboard and Swoosh mailbox preview in development
if Application.compile_env(:bright, :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
scope "/dev" do
pipe_through :browser
live_dashboard "/dashboard", metrics: BrightWeb.Telemetry
forward "/mailbox", Plug.Swoosh.MailboxPreview
end
end
## Authentication routes
scope "/", BrightWeb do
pipe_through [:browser]
end
end