clacks/lib/clacks_web/router.ex

97 lines
2.6 KiB
Elixir
Raw Normal View History

2019-09-28 22:30:55 +00:00
defmodule ClacksWeb.Router do
use ClacksWeb, :router
pipeline :browser do
plug :accepts, ["html"]
2019-10-06 23:41:18 +00:00
plug ClacksWeb.Plug.Format
2019-09-28 22:30:55 +00:00
plug :fetch_session
plug :fetch_flash
plug :protect_from_forgery
plug :put_secure_browser_headers
2019-10-06 23:41:18 +00:00
end
pipeline :browser_maybe_authenticated do
2019-10-02 21:25:35 +00:00
plug ClacksWeb.Plug.WebAuthenticate, on_failure: :pass
end
pipeline :browser_authenticated do
plug ClacksWeb.Plug.WebAuthenticate, on_failure: :redirect_to_login
2019-09-28 22:30:55 +00:00
end
2019-09-29 01:57:11 +00:00
pipeline :activitypub do
2021-08-26 03:15:09 +00:00
plug :accepts, ["activity+json", "json", "html"]
2019-09-28 22:30:55 +00:00
end
2019-10-06 23:41:18 +00:00
pipeline :browser_or_activitypub do
2021-08-26 03:15:09 +00:00
plug :accepts, ["html", "activity+json", "json"]
2019-10-06 23:41:18 +00:00
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
2019-09-28 22:30:55 +00:00
scope "/", ClacksWeb do
pipe_through :browser
2019-10-02 21:25:35 +00:00
get "/login", LoginController, :login
post "/login", LoginController, :login_post
2020-01-16 02:24:35 +00:00
post "/logout", LoginController, :logout
2019-10-02 21:25:35 +00:00
end
2019-10-06 23:41:18 +00:00
scope "/", ClacksWeb do
pipe_through :browser
pipe_through :browser_maybe_authenticated
get "/", FrontendController, :index
end
2019-10-02 21:25:35 +00:00
scope "/", ClacksWeb do
pipe_through :browser
pipe_through :browser_authenticated
2020-04-23 02:54:46 +00:00
post "/post", FrontendController, :post_status
2020-04-25 16:30:47 +00:00
get "/status/:id/reply", FrontendController, :reply
2020-04-26 02:28:30 +00:00
get "/search", FrontendController, :search
2020-04-26 18:45:51 +00:00
get "/actors/:id", FrontendController, :actor
2020-04-26 22:55:44 +00:00
post "/actors/:id/follow", FrontendController, :follow
post "/actors/:id/unfollow", FrontendController, :unfollow
2020-05-24 20:26:10 +00:00
get "/notifications", FrontendController, :notifications
2019-09-28 22:30:55 +00:00
end
2019-09-29 01:57:11 +00:00
scope "/", ClacksWeb do
pipe_through :activitypub
2019-10-06 23:41:18 +00:00
get "/users/:username/followers", ActorController, :followers
get "/users/:username/following", ActorController, :following
get "/users/:username/outbox", OutboxController, :outbox
2019-10-01 16:35:27 +00:00
2019-10-01 22:39:17 +00:00
post "/inbox", InboxController, :shared
2019-10-06 23:41:18 +00:00
post "/users/:username/inbox", InboxController, :user_specific
2019-10-01 22:39:17 +00:00
2019-10-01 16:35:27 +00:00
get "/.well-known/webfinger", WebFingerController, :get
2019-09-29 01:57:11 +00:00
end
2019-10-06 23:41:18 +00:00
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
2020-04-23 02:54:46 +00:00
get "/status/:id", FrontendController, :status
2019-10-06 23:41:18 +00:00
end
2019-09-28 22:30:55 +00:00
# Other scopes may use custom stacks.
# scope "/api", ClacksWeb do
# pipe_through :api
# end
end