clacks/lib/clacks_web/router.ex

91 lines
2.3 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
plug :accepts, ["activity+json", "html"]
2019-09-28 22:30:55 +00:00
end
2019-10-06 23:41:18 +00:00
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
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
post "/logout", LoginController, :logout_post
end
2019-10-06 23:41:18 +00:00
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
2019-10-02 21:25:35 +00:00
scope "/", ClacksWeb do
pipe_through :browser
pipe_through :browser_authenticated
2019-09-28 22:30:55 +00:00
end
2019-09-29 01:57:11 +00:00
scope "/", ClacksWeb do
pipe_through :activitypub
get "/objects/:id", ObjectsController, :get
2019-10-02 15:12:34 +00:00
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
end
2019-09-28 22:30:55 +00:00
# Other scopes may use custom stacks.
# scope "/api", ClacksWeb do
# pipe_through :api
# end
end