Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Add .well-known/matrix/client to clientapi #2551

Merged
merged 4 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clientapi/clientapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func AddPublicRoutes(

routing.Setup(
base.PublicClientAPIMux,
base.PublicWellKnownAPIMux,
base.SynapseAdminMux,
base.DendriteAdminMux,
cfg, rsAPI, asAPI,
Expand Down
22 changes: 21 additions & 1 deletion clientapi/routing/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import (
// applied:
// nolint: gocyclo
func Setup(
publicAPIMux, synapseAdminRouter, dendriteAdminRouter *mux.Router,
publicAPIMux, wkMux, synapseAdminRouter, dendriteAdminRouter *mux.Router,
cfg *config.ClientAPI,
rsAPI roomserverAPI.ClientRoomserverAPI,
asAPI appserviceAPI.AppServiceInternalAPI,
Expand All @@ -74,6 +74,26 @@ func Setup(
unstableFeatures["org.matrix."+msc] = true
}

if cfg.Matrix.WellKnownClientName != "" {
logrus.Infof("Setting m.homeserver base_url as %s at /.well-known/matrix/client", cfg.Matrix.WellKnownClientName)
wkMux.Handle("/client", httputil.MakeExternalAPI("wellknown", func(r *http.Request) util.JSONResponse {
return util.JSONResponse{
Code: http.StatusOK,
JSON: struct {
HomeserverName struct {
BaseUrl string `json:"base_url"`
} `json:"m.homeserver"`
}{
HomeserverName: struct {
BaseUrl string `json:"base_url"`
}{
BaseUrl: cfg.Matrix.WellKnownClientName,
},
},
}
})).Methods(http.MethodGet, http.MethodOptions)
}

publicAPIMux.Handle("/versions",
httputil.MakeExternalAPI("versions", func(req *http.Request) util.JSONResponse {
return util.JSONResponse{
Expand Down
4 changes: 4 additions & 0 deletions dendrite-sample.monolith.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ global:
# e.g. localhost:443
well_known_server_name: ""

# The server name to delegate client-server communications to, with optional port
# e.g. localhost:443
well_known_client_name: ""

# Lists of domains that the server will trust as identity servers to verify third
# party identifiers such as phone numbers and email addresses.
trusted_third_party_id_servers:
Expand Down
4 changes: 4 additions & 0 deletions dendrite-sample.polylith.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ global:
# e.g. localhost:443
well_known_server_name: ""

# The server name to delegate client-server communications to, with optional port
# e.g. localhost:443
well_known_client_name: ""

# Lists of domains that the server will trust as identity servers to verify third
# party identifiers such as phone numbers and email addresses.
trusted_third_party_id_servers:
Expand Down
3 changes: 3 additions & 0 deletions setup/config/config_global.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ type Global struct {
// The server name to delegate server-server communications to, with optional port
WellKnownServerName string `yaml:"well_known_server_name"`

// The server name to delegate client-server communications to, with optional port
WellKnownClientName string `yaml:"well_known_client_name"`

// Disables federation. Dendrite will not be able to make any outbound HTTP requests
// to other servers and the federation API will not be exposed.
DisableFederation bool `yaml:"disable_federation"`
Expand Down
1 change: 1 addition & 0 deletions setup/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ global:
key_id: ed25519:auto
key_validity_period: 168h0m0s
well_known_server_name: "localhost:443"
well_known_client_name: "localhost:443"
trusted_third_party_id_servers:
- matrix.org
- vector.im
Expand Down