GamendWeb.Router.Shared (gamend_web v1.0.1215)

Copy Markdown View Source

Route macros a host app mounts to get the server's HTTP surface.

A host owns its own router; this module supplies the routes rather than imposing a router, so you choose which surfaces exist. Import it, declare the pipelines, then call the groups you want:

defmodule MyGame.Router do
  use Phoenix.Router
  import GamendWeb.Router.Shared

  gamend_pipelines()

  gamend_api_routes()
  gamend_public_api_routes()
  gamend_authenticated_live_routes()
  gamend_admin_live_routes(GamendWeb.Router.Shared.require_admin_on_mount())
end

Leaving a group out removes those endpoints entirely — that is the supported way to ship a smaller surface, rather than deleting files from the dependency.

Groups

MacroMounts
gamend_pipelines/0The :browser, :api, :api_auth and :api_admin pipelines the rest expect. Call it first.
gamend_api_routes/0Auth, current user, lobbies, chat, KV, groups, parties, friends, notifications, quests, tournaments, matchmaking - the whole player-facing API.
gamend_public_api_routes/0Unauthenticated listings, each behind its own LIST_*_ENABLED flag.
gamend_api_auth_routes/0, gamend_oauth_routes/0Login, registration and the OAuth provider flows.
gamend_api_docs_routes/0The OpenAPI spec and Swagger UI at /api/docs.
gamend_authenticated_live_routes/0Player-facing LiveViews (lobbies, chat, quests, settings).
gamend_admin_live_routes/1The /admin console. Takes the on_mount hook from require_admin_on_mount/0.
gamend_admin_api_routes/0Admin HTTP mirrors of every console action.
gamend_static_page_routes/0, gamend_support_routes/0Host pages and support endpoints.
gamend_configured_page_fallback_routes/0Catch-all for theme-configured pages. Mount last.

The narrower macros (gamend_chat_api_routes/0, gamend_quest_api_routes/0 and so on) are the pieces the aggregate macros above are built from; call them directly when you want one subsystem without its neighbours.

Summary

Functions

Core's admin LiveView routes, optionally extended with host-specific ones.

Every core API route. :chat_update swaps the controller behind PATCH /api/v1/chat/messages/:id for a host that moderates its own edits.

Core's authenticated LiveView routes, extendable the same way as the admin ones.

Core's public LiveView routes, extendable with host-specific ones via :do.

Core's static pages. :home swaps the controller behind / for a host's own (action :home); overriding by declaring the route first would compile to an unreachable clause.

Functions

browser_headers()

current_user_on_mount()

gamend_account_lobby_api_routes()

(macro)

gamend_admin_api_routes()

(macro)

gamend_admin_chat_quest_api_routes()

(macro)

gamend_admin_kv_leaderboard_api_routes()

(macro)

gamend_admin_live_routes(on_mount, opts \\ [])

(macro)

Core's admin LiveView routes, optionally extended with host-specific ones.

The do block is spliced into the same live_session, so host routes get the admin pipeline and on_mount chain without the host restating them:

gamend_admin_live_routes @require_admin_on_mount do
  live "/admin/my_thing", MyThingLive, :index
end

It exists so a host that needs one extra admin page does not fork the whole list to get it. A fork looks harmless and then silently rots — every core admin page added afterwards is missing from that host, with no error, just a 404 nobody connects to the change that caused it.

gamend_admin_management_api_routes()

(macro)

gamend_api_auth_routes()

(macro)

gamend_api_docs_routes()

(macro)

gamend_api_routes(opts \\ [])

(macro)

Every core API route. :chat_update swaps the controller behind PATCH /api/v1/chat/messages/:id for a host that moderates its own edits.

gamend_authenticated_live_routes(on_mount, opts \\ [])

(macro)

Core's authenticated LiveView routes, extendable the same way as the admin ones.

:do splices host routes into the same live_session; :chat swaps the chat LiveView for a host's own. The session name is fixed, so a host cannot declare a second live_session :require_authenticated_user of its own — it extends this one or forks the lot.

gamend_chat_api_routes(opts \\ [])

(macro)

gamend_configured_page_fallback_routes()

(macro)

gamend_current_user_routes(on_mount, opts \\ [])

(macro)

Core's public LiveView routes, extendable with host-specific ones via :do.

Same reasoning as the admin and authenticated variants: live_session :current_user can only be declared once, so a host adding one public page extends this rather than restating core's list.

gamend_friend_notification_api_routes()

(macro)

gamend_group_api_routes()

(macro)

gamend_group_mutation_api_routes()

(macro)

gamend_hook_leaderboard_party_api_routes()

(macro)

gamend_kv_api_routes()

(macro)

gamend_matchmaking_api_routes()

(macro)

gamend_oauth_routes()

(macro)

gamend_pipelines()

(macro)

gamend_public_api_routes()

(macro)

gamend_quest_api_routes()

(macro)

gamend_static_page_routes(opts \\ [])

(macro)

Core's static pages. :home swaps the controller behind / for a host's own (action :home); overriding by declaring the route first would compile to an unreachable clause.

gamend_support_routes()

(macro)

gamend_tournament_api_routes()

(macro)

oban_headers()

require_admin_on_mount()

require_authenticated_on_mount()

swagger_headers()