mirror of
https://gitlab.com/famedly/conduit.git
synced 2024-12-27 21:13:47 +03:00
Merge branch 'not-found' into 'next'
Add a not-found route See merge request famedly/conduit!306
This commit is contained in:
commit
5a99460a4c
1 changed files with 11 additions and 2 deletions
13
src/main.rs
13
src/main.rs
|
@ -11,6 +11,7 @@ use std::{future::Future, io, net::SocketAddr, sync::Arc, time::Duration};
|
||||||
|
|
||||||
use axum::{
|
use axum::{
|
||||||
extract::{FromRequest, MatchedPath},
|
extract::{FromRequest, MatchedPath},
|
||||||
|
handler::Handler,
|
||||||
response::IntoResponse,
|
response::IntoResponse,
|
||||||
routing::{get, on, MethodFilter},
|
routing::{get, on, MethodFilter},
|
||||||
Router,
|
Router,
|
||||||
|
@ -22,10 +23,13 @@ use figment::{
|
||||||
};
|
};
|
||||||
use http::{
|
use http::{
|
||||||
header::{self, HeaderName},
|
header::{self, HeaderName},
|
||||||
Method,
|
Method, Uri,
|
||||||
};
|
};
|
||||||
use opentelemetry::trace::{FutureExt, Tracer};
|
use opentelemetry::trace::{FutureExt, Tracer};
|
||||||
use ruma::{api::IncomingRequest, Outgoing};
|
use ruma::{
|
||||||
|
api::{client::error::ErrorKind, IncomingRequest},
|
||||||
|
Outgoing,
|
||||||
|
};
|
||||||
use tokio::{signal, sync::RwLock};
|
use tokio::{signal, sync::RwLock};
|
||||||
use tower::ServiceBuilder;
|
use tower::ServiceBuilder;
|
||||||
use tower_http::{
|
use tower_http::{
|
||||||
|
@ -321,6 +325,7 @@ fn routes() -> Router {
|
||||||
.ruma_route(server_server::get_profile_information_route)
|
.ruma_route(server_server::get_profile_information_route)
|
||||||
.ruma_route(server_server::get_keys_route)
|
.ruma_route(server_server::get_keys_route)
|
||||||
.ruma_route(server_server::claim_keys_route)
|
.ruma_route(server_server::claim_keys_route)
|
||||||
|
.fallback(not_found.into_service())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn shutdown_signal(handle: ServerHandle) {
|
async fn shutdown_signal(handle: ServerHandle) {
|
||||||
|
@ -349,6 +354,10 @@ async fn shutdown_signal(handle: ServerHandle) {
|
||||||
handle.graceful_shutdown(Some(Duration::from_secs(30)));
|
handle.graceful_shutdown(Some(Duration::from_secs(30)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn not_found(_uri: Uri) -> impl IntoResponse {
|
||||||
|
Error::BadRequest(ErrorKind::NotFound, "Unknown or unimplemented route")
|
||||||
|
}
|
||||||
|
|
||||||
trait RouterExt {
|
trait RouterExt {
|
||||||
fn ruma_route<H, T>(self, handler: H) -> Self
|
fn ruma_route<H, T>(self, handler: H) -> Self
|
||||||
where
|
where
|
||||||
|
|
Loading…
Reference in a new issue