Restructure router rules

This commit is contained in:
Pim Kunis 2021-08-17 22:50:15 +02:00
parent 02edff90e7
commit 8696b0fb96
3 changed files with 35 additions and 18 deletions

View file

@ -1,4 +1,4 @@
defmodule MatrixServerWeb.Client.AuthenticateClientPlug do defmodule MatrixServerWeb.Client.Plug.AuthenticateClient do
import MatrixServerWeb.Error import MatrixServerWeb.Error
import Plug.Conn import Plug.Conn

View file

@ -0,0 +1,8 @@
defmodule MatrixServerWeb.Federation.EventController do
use MatrixServerWeb, :controller
use MatrixServerWeb.Federation.AuthenticateServer
def event(conn, %{"event_id" => event_id}) do
end
end

View file

@ -1,28 +1,30 @@
defmodule MatrixServerWeb.Router do defmodule MatrixServerWeb.Router do
use MatrixServerWeb, :router use MatrixServerWeb, :router
alias MatrixServerWeb.Client.AuthenticateClientPlug alias MatrixServerWeb.Client.Plug.AuthenticateClient
# TODO: might be able to handle malformed JSON with custom body reader: # TODO: might be able to handle malformed JSON with custom body reader:
# https://elixirforum.com/t/write-malformed-json-in-the-body-plug/30578/13 # https://elixirforum.com/t/write-malformed-json-in-the-body-plug/30578/13
# TODO: Split endpoint into client and federation?
pipeline :public do pipeline :public do
plug :accepts, ["json"] plug :accepts, ["json"]
end end
pipeline :authenticate_client do pipeline :authenticate_client do
plug :accepts, ["json"] plug :accepts, ["json"]
plug AuthenticateClientPlug plug AuthenticateClient
end end
pipeline :authenticate_server do pipeline :authenticate_server do
plug :accepts, ["json"] plug :accepts, ["json"]
end end
scope "/_matrix", MatrixServerWeb do # Public client endpoint.
scope "/_matrix/client", MatrixServerWeb.Client do
pipe_through :public pipe_through :public
scope "/client", Client do
scope "/r0" do scope "/r0" do
post "/register", RegisterController, :register post "/register", RegisterController, :register
get "/register/available", AccountController, :available get "/register/available", AccountController, :available
@ -33,15 +35,18 @@ defmodule MatrixServerWeb.Router do
get "/versions", InfoController, :versions get "/versions", InfoController, :versions
end end
scope "/key/v2", Federation do # Public federation endpoint.
scope "/_matrix", MatrixServerWeb.Federation do
scope "/key/v2" do
get "/server", KeyController, :get_signing_keys get "/server", KeyController, :get_signing_keys
end end
end end
scope "/_matrix", MatrixServerWeb.Client do # Authenticated client endpoint.
scope "/_matrix/client", MatrixServerWeb.Client do
pipe_through :authenticate_client pipe_through :authenticate_client
scope "/client/r0" do scope "/r0" do
get "/account/whoami", AccountController, :whoami get "/account/whoami", AccountController, :whoami
post "/logout", AccountController, :logout post "/logout", AccountController, :logout
post "/logout/all", AccountController, :logout_all post "/logout/all", AccountController, :logout_all
@ -53,10 +58,14 @@ defmodule MatrixServerWeb.Router do
end end
end end
scope "/_matrix", MatrixServerWeb.Federation do # Authenticated federation endpoint.
scope "/_matrix/federation", MatrixServerWeb.Federation do
pipe_through :authenticate_server pipe_through :authenticate_server
get "/federation/v1/query/profile", QueryController, :profile scope "/v1" do
get "/query/profile", QueryController, :profile
get "/event/:event_id", EventController, :event
end
end end
scope "/", MatrixServerWeb.Client do scope "/", MatrixServerWeb.Client do