clacks/lib/clacks_web/router.ex

91 lines
2.3 KiB
Elixir

defmodule ClacksWeb.Router do
use ClacksWeb, :router
pipeline :browser do
plug :accepts, ["html"]
plug ClacksWeb.Plug.Format
plug :fetch_session
plug :fetch_flash
plug :protect_from_forgery
plug :put_secure_browser_headers
end
pipeline :browser_maybe_authenticated do
plug ClacksWeb.Plug.WebAuthenticate, on_failure: :pass
end
pipeline :browser_authenticated do
plug ClacksWeb.Plug.WebAuthenticate, on_failure: :redirect_to_login
end
pipeline :activitypub do
plug :accepts, ["activity+json", "html"]
end
pipeline :browser_or_activitypub do
plug :accepts, ["html", "activity+json"]
plug ClacksWeb.Plug.Format
plug :browser_if_html
end
defp browser_if_html(%Plug.Conn{assigns: %{format: "html"}} = conn, _opts) do
conn
|> fetch_session()
|> fetch_flash()
|> protect_from_forgery()
|> put_secure_browser_headers()
end
defp browser_if_html(conn, _opts), do: conn
scope "/", ClacksWeb do
pipe_through :browser
get "/login", LoginController, :login
post "/login", LoginController, :login_post
post "/logout", LoginController, :logout
end
scope "/", ClacksWeb do
pipe_through :browser
pipe_through :browser_maybe_authenticated
get "/", FrontendController, :index
get "/status/:id", FrontendController, :status
post "/post", FrontendController, :post_status
end
scope "/", ClacksWeb do
pipe_through :browser
pipe_through :browser_authenticated
end
scope "/", ClacksWeb do
pipe_through :activitypub
get "/objects/:id", ObjectsController, :get
get "/users/:username/followers", ActorController, :followers
get "/users/:username/following", ActorController, :following
get "/users/:username/outbox", OutboxController, :outbox
post "/inbox", InboxController, :shared
post "/users/:username/inbox", InboxController, :user_specific
get "/.well-known/webfinger", WebFingerController, :get
end
scope "/", ClacksWeb do
pipe_through :browser_or_activitypub
pipe_through :browser_maybe_authenticated
get "/users/:username", ActorController, :get
get "/activities/:id", ActivitiesController, :get
end
# Other scopes may use custom stacks.
# scope "/api", ClacksWeb do
# pipe_through :api
# end
end