mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-17 07:41:23 +01:00
Split routes into components
This commit is contained in:
parent
b0d1cc1b63
commit
d62d0e2f0e
1 changed files with 64 additions and 39 deletions
103
src/cli/serve.rs
103
src/cli/serve.rs
|
|
@ -249,10 +249,37 @@ async fn unrecognized_method(
|
||||||
Ok(inner)
|
Ok(inner)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_lines)]
|
/// Routes for legacy unauthenticated `/_matrix/media/*` APIs (used by both
|
||||||
fn routes(config: &Config) -> Router {
|
/// clients and federation)
|
||||||
|
fn legacy_media_routes(config: &Config) -> Router {
|
||||||
|
use client_server as c2s;
|
||||||
|
|
||||||
|
let router = Router::new();
|
||||||
|
|
||||||
|
// deprecated, but unproblematic
|
||||||
|
let router = router.ruma_route(c2s::get_media_config_legacy_route);
|
||||||
|
|
||||||
|
if config.serve_media_unauthenticated {
|
||||||
|
router
|
||||||
|
.ruma_route(c2s::get_content_legacy_route)
|
||||||
|
.ruma_route(c2s::get_content_as_filename_legacy_route)
|
||||||
|
.ruma_route(c2s::get_content_thumbnail_legacy_route)
|
||||||
|
} else {
|
||||||
|
router
|
||||||
|
.route(
|
||||||
|
"/_matrix/media/v3/download/*path",
|
||||||
|
any(unauthenticated_media_disabled),
|
||||||
|
)
|
||||||
|
.route(
|
||||||
|
"/_matrix/media/v3/thumbnail/*path",
|
||||||
|
any(unauthenticated_media_disabled),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_lines)]
|
||||||
|
fn client_routes() -> Router {
|
||||||
use client_server as c2s;
|
use client_server as c2s;
|
||||||
use server_server as s2s;
|
|
||||||
|
|
||||||
let router = Router::new()
|
let router = Router::new()
|
||||||
.ruma_route(c2s::get_supported_versions_route)
|
.ruma_route(c2s::get_supported_versions_route)
|
||||||
|
|
@ -345,25 +372,6 @@ fn routes(config: &Config) -> Router {
|
||||||
.ruma_route(c2s::turn_server_route)
|
.ruma_route(c2s::turn_server_route)
|
||||||
.ruma_route(c2s::send_event_to_device_route);
|
.ruma_route(c2s::send_event_to_device_route);
|
||||||
|
|
||||||
// deprecated, but unproblematic
|
|
||||||
let router = router.ruma_route(c2s::get_media_config_legacy_route);
|
|
||||||
let router = if config.serve_media_unauthenticated {
|
|
||||||
router
|
|
||||||
.ruma_route(c2s::get_content_legacy_route)
|
|
||||||
.ruma_route(c2s::get_content_as_filename_legacy_route)
|
|
||||||
.ruma_route(c2s::get_content_thumbnail_legacy_route)
|
|
||||||
} else {
|
|
||||||
router
|
|
||||||
.route(
|
|
||||||
"/_matrix/media/v3/download/*path",
|
|
||||||
any(unauthenticated_media_disabled),
|
|
||||||
)
|
|
||||||
.route(
|
|
||||||
"/_matrix/media/v3/thumbnail/*path",
|
|
||||||
any(unauthenticated_media_disabled),
|
|
||||||
)
|
|
||||||
};
|
|
||||||
|
|
||||||
// authenticated media
|
// authenticated media
|
||||||
let router = router
|
let router = router
|
||||||
.ruma_route(c2s::get_media_config_route)
|
.ruma_route(c2s::get_media_config_route)
|
||||||
|
|
@ -419,16 +427,7 @@ fn routes(config: &Config) -> Router {
|
||||||
.put(c2s::send_state_event_for_empty_key_route),
|
.put(c2s::send_state_event_for_empty_key_route),
|
||||||
);
|
);
|
||||||
|
|
||||||
let router = if config.observability.metrics.enable {
|
router
|
||||||
router.route(
|
|
||||||
"/metrics",
|
|
||||||
get(|| async { observability::METRICS.export() }),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
router
|
|
||||||
};
|
|
||||||
|
|
||||||
let router = router
|
|
||||||
.route(
|
.route(
|
||||||
"/_matrix/client/r0/rooms/:room_id/initialSync",
|
"/_matrix/client/r0/rooms/:room_id/initialSync",
|
||||||
get(initial_sync),
|
get(initial_sync),
|
||||||
|
|
@ -437,15 +436,13 @@ fn routes(config: &Config) -> Router {
|
||||||
"/_matrix/client/v3/rooms/:room_id/initialSync",
|
"/_matrix/client/v3/rooms/:room_id/initialSync",
|
||||||
get(initial_sync),
|
get(initial_sync),
|
||||||
)
|
)
|
||||||
.route("/", get(it_works))
|
}
|
||||||
.fallback(not_found);
|
|
||||||
|
|
||||||
let router = router
|
fn federation_routes(config: &Config) -> Router {
|
||||||
.route("/.well-known/matrix/client", get(well_known::client))
|
use server_server as s2s;
|
||||||
.route("/.well-known/matrix/server", get(well_known::server));
|
|
||||||
|
|
||||||
if config.federation.enable {
|
if config.federation.enable {
|
||||||
router
|
Router::new()
|
||||||
.ruma_route(s2s::get_server_version_route)
|
.ruma_route(s2s::get_server_version_route)
|
||||||
.route("/_matrix/key/v2/server", get(s2s::get_server_keys_route))
|
.route("/_matrix/key/v2/server", get(s2s::get_server_keys_route))
|
||||||
.route(
|
.route(
|
||||||
|
|
@ -473,12 +470,40 @@ fn routes(config: &Config) -> Router {
|
||||||
.ruma_route(s2s::media_download_route)
|
.ruma_route(s2s::media_download_route)
|
||||||
.ruma_route(s2s::media_thumbnail_route)
|
.ruma_route(s2s::media_thumbnail_route)
|
||||||
} else {
|
} else {
|
||||||
router
|
Router::new()
|
||||||
.route("/_matrix/federation/*path", any(federation_disabled))
|
.route("/_matrix/federation/*path", any(federation_disabled))
|
||||||
.route("/_matrix/key/*path", any(federation_disabled))
|
.route("/_matrix/key/*path", any(federation_disabled))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn metrics_routes(config: &Config) -> Router {
|
||||||
|
if config.observability.metrics.enable {
|
||||||
|
Router::new().route(
|
||||||
|
"/metrics",
|
||||||
|
get(|| async { observability::METRICS.export() }),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
Router::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn well_known_routes() -> Router {
|
||||||
|
Router::new()
|
||||||
|
.route("/.well-known/matrix/client", get(well_known::client))
|
||||||
|
.route("/.well-known/matrix/server", get(well_known::server))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn routes(config: &Config) -> Router {
|
||||||
|
Router::new()
|
||||||
|
.merge(client_routes())
|
||||||
|
.merge(federation_routes(config))
|
||||||
|
.merge(legacy_media_routes(config))
|
||||||
|
.merge(well_known_routes())
|
||||||
|
.merge(metrics_routes(config))
|
||||||
|
.route("/", get(it_works))
|
||||||
|
.fallback(not_found)
|
||||||
|
}
|
||||||
|
|
||||||
async fn shutdown_signal(handles: Vec<ServerHandle>) {
|
async fn shutdown_signal(handles: Vec<ServerHandle>) {
|
||||||
let ctrl_c = async {
|
let ctrl_c = async {
|
||||||
signal::ctrl_c().await.expect("failed to install Ctrl+C handler");
|
signal::ctrl_c().await.expect("failed to install Ctrl+C handler");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue