2021-06-22 12:09:25 +00:00
|
|
|
defmodule MatrixServerWeb.Router do
|
|
|
|
use MatrixServerWeb, :router
|
|
|
|
|
2021-08-17 20:50:15 +00:00
|
|
|
alias MatrixServerWeb.Client.Plug.AuthenticateClient
|
2021-08-08 17:20:10 +00:00
|
|
|
|
|
|
|
# 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
|
2021-06-25 23:14:09 +00:00
|
|
|
|
2021-08-17 20:50:15 +00:00
|
|
|
# TODO: Split endpoint into client and federation?
|
|
|
|
|
2021-06-25 22:29:33 +00:00
|
|
|
pipeline :public do
|
2021-06-22 12:09:25 +00:00
|
|
|
plug :accepts, ["json"]
|
|
|
|
end
|
|
|
|
|
2021-08-06 21:14:27 +00:00
|
|
|
pipeline :authenticate_client do
|
2021-06-25 22:29:33 +00:00
|
|
|
plug :accepts, ["json"]
|
2021-08-17 20:50:15 +00:00
|
|
|
plug AuthenticateClient
|
2021-06-25 22:29:33 +00:00
|
|
|
end
|
|
|
|
|
2021-08-06 21:14:27 +00:00
|
|
|
pipeline :authenticate_server do
|
|
|
|
plug :accepts, ["json"]
|
|
|
|
end
|
|
|
|
|
2021-08-17 20:50:15 +00:00
|
|
|
# Public client endpoint.
|
|
|
|
scope "/_matrix/client", MatrixServerWeb.Client do
|
2021-06-25 22:29:33 +00:00
|
|
|
pipe_through :public
|
2021-06-22 21:04:37 +00:00
|
|
|
|
2021-08-17 20:50:15 +00:00
|
|
|
scope "/r0" do
|
|
|
|
post "/register", RegisterController, :register
|
|
|
|
get "/register/available", AccountController, :available
|
|
|
|
get "/login", LoginController, :login_types
|
|
|
|
post "/login", LoginController, :login
|
2021-06-22 21:04:37 +00:00
|
|
|
end
|
2021-06-22 23:49:47 +00:00
|
|
|
|
2021-08-17 20:50:15 +00:00
|
|
|
get "/versions", InfoController, :versions
|
|
|
|
end
|
|
|
|
|
|
|
|
# Public federation endpoint.
|
|
|
|
scope "/_matrix", MatrixServerWeb.Federation do
|
|
|
|
scope "/key/v2" do
|
2021-08-06 13:52:03 +00:00
|
|
|
get "/server", KeyController, :get_signing_keys
|
|
|
|
end
|
2021-06-22 12:09:25 +00:00
|
|
|
end
|
2021-06-25 22:29:33 +00:00
|
|
|
|
2021-08-17 20:50:15 +00:00
|
|
|
# Authenticated client endpoint.
|
|
|
|
scope "/_matrix/client", MatrixServerWeb.Client do
|
2021-08-06 21:14:27 +00:00
|
|
|
pipe_through :authenticate_client
|
2021-06-25 22:29:33 +00:00
|
|
|
|
2021-08-17 20:50:15 +00:00
|
|
|
scope "/r0" do
|
2021-06-25 22:29:33 +00:00
|
|
|
get "/account/whoami", AccountController, :whoami
|
2021-06-27 20:24:54 +00:00
|
|
|
post "/logout", AccountController, :logout
|
|
|
|
post "/logout/all", AccountController, :logout_all
|
2021-07-10 21:16:00 +00:00
|
|
|
post "/createRoom", RoomController, :create
|
2021-07-30 13:56:24 +00:00
|
|
|
|
|
|
|
scope "/directory/room" do
|
|
|
|
put "/:alias", AliasesController, :create
|
|
|
|
end
|
2021-06-25 22:29:33 +00:00
|
|
|
end
|
|
|
|
end
|
2021-06-26 20:02:18 +00:00
|
|
|
|
2021-08-17 20:50:15 +00:00
|
|
|
# Authenticated federation endpoint.
|
|
|
|
scope "/_matrix/federation", MatrixServerWeb.Federation do
|
2021-08-08 17:20:10 +00:00
|
|
|
pipe_through :authenticate_server
|
2021-08-06 21:14:27 +00:00
|
|
|
|
2021-08-17 20:50:15 +00:00
|
|
|
scope "/v1" do
|
|
|
|
get "/query/profile", QueryController, :profile
|
|
|
|
get "/event/:event_id", EventController, :event
|
2021-08-21 19:39:28 +00:00
|
|
|
get "/state/:room_id", EventController, :state
|
2021-08-17 20:50:15 +00:00
|
|
|
end
|
2021-08-06 21:14:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
scope "/", MatrixServerWeb.Client do
|
2021-06-26 20:02:18 +00:00
|
|
|
match :*, "/*path", InfoController, :unrecognized
|
|
|
|
end
|
2021-06-22 12:09:25 +00:00
|
|
|
end
|