clacks/lib/clacks_web/router.ex

97 lines
2.6 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", "json", "html"]
end
pipeline :browser_or_activitypub do
plug :accepts, ["html", "activity+json", "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
end
scope "/", ClacksWeb do
pipe_through :browser
pipe_through :browser_authenticated
post "/post", FrontendController, :post_status
get "/status/:id/reply", FrontendController, :reply
get "/search", FrontendController, :search
get "/actors/:id", FrontendController, :actor
post "/actors/:id/follow", FrontendController, :follow
post "/actors/:id/unfollow", FrontendController, :unfollow
get "/notifications", FrontendController, :notifications
end
scope "/", ClacksWeb do
pipe_through :activitypub
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
get "/objects/:id", ObjectsController, :get
get "/status/:id", FrontendController, :status
end
# Other scopes may use custom stacks.
# scope "/api", ClacksWeb do
# pipe_through :api
# end
end