bonfire-app/lib/web/router.ex

159 lines
4.9 KiB
Elixir
Raw Normal View History

2020-11-10 16:00:02 +00:00
defmodule Bonfire.Web.Router do
2022-05-04 02:13:47 +00:00
use Bonfire.UI.Common.Web, :router
2021-07-07 07:48:46 +00:00
# use Plug.ErrorHandler
2022-01-15 03:31:08 +00:00
alias Bonfire.Common.Config
2020-11-10 16:00:02 +00:00
2022-05-03 23:03:07 +00:00
pipeline :load_current_auth do
2022-09-12 04:34:14 +00:00
plug(Bonfire.UI.Me.Plugs.LoadCurrentAccount)
plug(Bonfire.UI.Me.Plugs.LoadCurrentUser)
2021-06-04 12:14:45 +00:00
end
# please note the order matters here, because of pipelines being defined in some module and re-used in others
2020-11-24 09:07:50 +00:00
2022-09-12 04:34:14 +00:00
use_if_enabled(Bonfire.UI.Common.Routes)
2021-03-02 14:38:17 +00:00
2022-10-20 06:57:11 +00:00
use_if_enabled(Bonfire.UI.Me.Routes)
2021-04-22 12:45:56 +00:00
# include routes for active Bonfire extensions (no need to comment out, they'll be skipped if not available or if disabled)
2022-10-20 03:23:50 +00:00
# TODO: automatically include all active extensions
2022-10-21 07:51:00 +00:00
# ui_extensions = Application.compile_env!(:bonfire, :extensions_grouped, Bonfire.Common.NavModule)
2022-10-20 06:57:11 +00:00
# |> Enum.flat_map(& Application.spec(&1, :modules) || [] )
# |> Enum.filter(& Code.ensure_loaded?(&1) and function_exported?(&1, :declare_routes, 0))
# |> debug()
# # quoted_use_if_enabled(ui_extensions)
2022-10-20 03:23:50 +00:00
# for extension <- ui_extensions do
2022-10-20 06:57:11 +00:00
# require extension
# extension.__using__(nil)
2022-10-20 03:23:50 +00:00
# end
2021-04-22 12:45:56 +00:00
2021-05-08 18:17:50 +00:00
# use_if_enabled Bonfire.Website.Web.Routes
2021-04-22 12:45:56 +00:00
2022-09-12 04:34:14 +00:00
use_if_enabled(Bonfire.UI.Social.Routes)
use_if_enabled(Bonfire.Boundaries.Web.Routes)
2021-04-22 12:45:56 +00:00
use_if_enabled(Bonfire.Pages.Web.Routes)
2022-09-12 04:34:14 +00:00
use_if_enabled(Bonfire.OpenID.Web.Routes)
2022-09-12 04:34:14 +00:00
use_if_enabled(Bonfire.Search.Web.Routes)
use_if_enabled(Bonfire.Tag.Web.Routes)
use_if_enabled(Bonfire.Classify.Web.Routes)
use_if_enabled(Bonfire.Geolocate.Web.Routes)
2021-04-22 12:45:56 +00:00
2022-09-12 04:34:14 +00:00
use_if_enabled(Bonfire.UI.Reflow.Routes)
use_if_enabled(Bonfire.UI.Coordination.Routes)
use_if_enabled(Bonfire.UI.Kanban.Routes)
use_if_enabled(Bonfire.Breadpub.Web.Routes)
use_if_enabled(Bonfire.Recyclapp.Routes)
use_if_enabled(Bonfire.Upcycle.Web.Routes)
2021-05-18 11:25:48 +00:00
2022-09-26 22:49:20 +00:00
use_if_enabled(RauversionExtension.UI.Routes)
2022-09-29 07:35:25 +00:00
use_if_enabled(Bonfire.Pages.Beacon.Web.Routes)
2022-11-27 10:00:21 +00:00
use_if_enabled(Bonfire.Encrypt.Web.Routes)
2022-10-20 06:57:11 +00:00
use_if_enabled(Bonfire.ExtensionTemplate.Web.Routes)
2022-09-29 07:35:25 +00:00
2021-04-22 12:45:56 +00:00
# include GraphQL API
2022-09-12 04:34:14 +00:00
use_if_enabled(Bonfire.API.GraphQL.Router)
2021-03-13 14:31:02 +00:00
# include federation routes
2022-09-12 04:34:14 +00:00
use_if_enabled(ActivityPubWeb.Router)
2021-03-13 14:31:02 +00:00
# include nodeinfo routes
2022-09-12 04:34:14 +00:00
use_if_enabled(NodeinfoWeb.Router)
2021-04-22 12:45:56 +00:00
2021-07-02 06:53:41 +00:00
# optionally include Livebook for developers
2022-10-20 06:57:11 +00:00
# use_if_enabled(Bonfire.Livebook.Web.Routes)
2021-07-02 06:53:41 +00:00
2021-12-17 04:33:24 +00:00
# optionally include Surface Catalogue for the stylebook
2022-09-12 04:34:14 +00:00
require_if_enabled(Surface.Catalogue.Router)
2021-03-13 14:31:02 +00:00
## Below you can define routes specific to your flavour of Bonfire (which aren't handled by extensions)
2020-11-24 09:07:50 +00:00
# pages anyone can view
2022-01-25 05:05:42 +00:00
scope "/" do
2022-09-12 04:34:14 +00:00
pipe_through(:browser)
2021-09-25 03:33:45 +00:00
2022-05-11 01:45:49 +00:00
# TODO: make the homepage non-live
2022-09-12 04:34:14 +00:00
live("/", Bonfire.Web.HomeLive, as: :home, private: %{cache: true})
live("/terms/:tab", Bonfire.Web.HomeLive, private: %{cache: true})
2022-06-17 12:27:57 +00:00
2021-01-09 12:50:23 +00:00
# a default homepage which you can customise (at path "/")
2022-05-11 01:45:49 +00:00
# can be replaced with something else (eg. bonfire_website extension or similar), in which case you may want to rename this default path (eg. to "/home")
# live "/", Bonfire.Website.HomeGuestLive, as: :landing
# live "/home", Bonfire.Web.HomeLive, as: :home
2021-01-02 12:01:50 +00:00
# get "/guest/error", Bonfire.UI.Common.ErrorController, as: :error_guest
2022-09-12 04:34:14 +00:00
live("/error", Bonfire.UI.Me.ErrorLive, as: :error)
2020-11-22 16:47:22 +00:00
end
2020-11-10 16:00:02 +00:00
2020-11-24 09:07:50 +00:00
# pages only guests can view
scope "/" do
2022-09-12 04:34:14 +00:00
pipe_through(:browser)
pipe_through(:guest_only)
2020-11-22 16:47:22 +00:00
end
2020-11-10 16:00:02 +00:00
2020-11-24 09:07:50 +00:00
# pages you need an account to view
scope "/" do
2022-09-12 04:34:14 +00:00
pipe_through(:browser)
pipe_through(:account_required)
end
2020-11-10 16:00:02 +00:00
2020-11-24 09:07:50 +00:00
# pages you need to view as a user
scope "/" do
2022-09-12 04:34:14 +00:00
pipe_through(:browser)
pipe_through(:user_required)
2022-09-12 04:34:14 +00:00
live("/dashboard", Bonfire.Web.HomeLive, as: :dashboard)
# live "/dashboard", Bonfire.UI.Social.FeedsLive, as: :dashboard
2020-11-24 09:07:50 +00:00
end
# pages only admins can view
2021-03-13 13:04:30 +00:00
scope "/settings/admin" do
2022-09-12 04:34:14 +00:00
pipe_through(:browser)
pipe_through(:admin_required)
2020-11-24 09:07:50 +00:00
end
2021-06-04 12:14:45 +00:00
scope "/" do
2022-09-12 04:34:14 +00:00
pipe_through(:browser)
2021-06-04 12:14:45 +00:00
2021-12-17 04:33:24 +00:00
# if module_enabled?(Surface.Catalogue.Router) do # FIXME - getting function surface_catalogue/1 is undefined or private
# Surface.Catalogue.Router.surface_catalogue "/ui/"
# end
2021-06-04 12:14:45 +00:00
if module_enabled?(Phoenix.LiveDashboard.Router) do
import Phoenix.LiveDashboard.Router
2022-09-12 04:34:14 +00:00
pipe_through(:admin_required)
2021-09-25 03:33:45 +00:00
2022-09-12 04:34:14 +00:00
live_dashboard("/admin/system",
2022-05-04 02:13:47 +00:00
ecto_repos: [Bonfire.Common.Repo],
2022-09-12 04:34:14 +00:00
ecto_psql_extras_options: [
long_running_queries: [threshold: "400 milliseconds"]
],
2022-02-24 18:39:19 +00:00
metrics: Bonfire.Web.Telemetry,
# metrics: FlamegraphsWeb.Telemetry,
additional_pages: [
2022-10-10 09:29:20 +00:00
flame_on: FlameOn.DashboardPage
# _profiler: {PhoenixProfiler.Dashboard, []}
2022-02-24 18:39:19 +00:00
]
2022-09-12 04:34:14 +00:00
)
2021-06-04 12:14:45 +00:00
end
end
2020-11-10 16:00:02 +00:00
if Mix.env() in [:dev, :test] do
scope "/" do
2022-09-12 04:34:14 +00:00
pipe_through(:browser)
2021-04-27 10:03:53 +00:00
2021-05-08 18:17:50 +00:00
if module_enabled?(Bamboo.SentEmailViewerPlug) do
2022-09-12 04:34:14 +00:00
forward("/admin/emails", Bamboo.SentEmailViewerPlug)
2021-04-27 10:03:53 +00:00
end
2020-11-10 16:00:02 +00:00
end
end
2021-05-03 17:01:22 +00:00
end
2022-09-12 04:34:14 +00:00
2022-10-20 03:23:50 +00:00
# generate initial reverse router (note that it will be re-generated at app start and when extensions are enabled/disabled)
Bonfire.Web.Endpoint.generate_reverse_router!()