From 8696b0fb96198066c697a8498d1f5b755cbe06ca Mon Sep 17 00:00:00 2001 From: Pim Kunis Date: Tue, 17 Aug 2021 22:50:15 +0200 Subject: [PATCH] Restructure router rules --- ..._client_plug.ex => authenticate_client.ex} | 2 +- .../controllers/event_controller.ex | 8 ++++ lib/matrix_server_web/router.ex | 43 +++++++++++-------- 3 files changed, 35 insertions(+), 18 deletions(-) rename lib/matrix_server_web/client/{authenticate_client_plug.ex => authenticate_client.ex} (92%) create mode 100644 lib/matrix_server_web/federation/controllers/event_controller.ex diff --git a/lib/matrix_server_web/client/authenticate_client_plug.ex b/lib/matrix_server_web/client/authenticate_client.ex similarity index 92% rename from lib/matrix_server_web/client/authenticate_client_plug.ex rename to lib/matrix_server_web/client/authenticate_client.ex index 7e8fea3..d72f1e1 100644 --- a/lib/matrix_server_web/client/authenticate_client_plug.ex +++ b/lib/matrix_server_web/client/authenticate_client.ex @@ -1,4 +1,4 @@ -defmodule MatrixServerWeb.Client.AuthenticateClientPlug do +defmodule MatrixServerWeb.Client.Plug.AuthenticateClient do import MatrixServerWeb.Error import Plug.Conn diff --git a/lib/matrix_server_web/federation/controllers/event_controller.ex b/lib/matrix_server_web/federation/controllers/event_controller.ex new file mode 100644 index 0000000..b3068c7 --- /dev/null +++ b/lib/matrix_server_web/federation/controllers/event_controller.ex @@ -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 diff --git a/lib/matrix_server_web/router.ex b/lib/matrix_server_web/router.ex index 57bf53b..821d301 100644 --- a/lib/matrix_server_web/router.ex +++ b/lib/matrix_server_web/router.ex @@ -1,47 +1,52 @@ defmodule MatrixServerWeb.Router do use MatrixServerWeb, :router - alias MatrixServerWeb.Client.AuthenticateClientPlug + alias MatrixServerWeb.Client.Plug.AuthenticateClient # 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 + # TODO: Split endpoint into client and federation? + pipeline :public do plug :accepts, ["json"] end pipeline :authenticate_client do plug :accepts, ["json"] - plug AuthenticateClientPlug + plug AuthenticateClient end pipeline :authenticate_server do plug :accepts, ["json"] end - scope "/_matrix", MatrixServerWeb do + # Public client endpoint. + scope "/_matrix/client", MatrixServerWeb.Client do pipe_through :public - scope "/client", Client do - scope "/r0" do - post "/register", RegisterController, :register - get "/register/available", AccountController, :available - get "/login", LoginController, :login_types - post "/login", LoginController, :login - end - - get "/versions", InfoController, :versions + scope "/r0" do + post "/register", RegisterController, :register + get "/register/available", AccountController, :available + get "/login", LoginController, :login_types + post "/login", LoginController, :login end - scope "/key/v2", Federation do + get "/versions", InfoController, :versions + end + + # Public federation endpoint. + scope "/_matrix", MatrixServerWeb.Federation do + scope "/key/v2" do get "/server", KeyController, :get_signing_keys end end - scope "/_matrix", MatrixServerWeb.Client do + # Authenticated client endpoint. + scope "/_matrix/client", MatrixServerWeb.Client do pipe_through :authenticate_client - scope "/client/r0" do + scope "/r0" do get "/account/whoami", AccountController, :whoami post "/logout", AccountController, :logout post "/logout/all", AccountController, :logout_all @@ -53,10 +58,14 @@ defmodule MatrixServerWeb.Router do end end - scope "/_matrix", MatrixServerWeb.Federation do + # Authenticated federation endpoint. + scope "/_matrix/federation", MatrixServerWeb.Federation do 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 scope "/", MatrixServerWeb.Client do