Add fallback route

This commit is contained in:
DefectingCat
2023-04-14 21:51:03 +08:00
parent a7bf4393cd
commit b132506863

View File

@ -1,7 +1,12 @@
use std::{net::SocketAddr, process::exit, sync::Arc};
use anyhow::Result;
use axum::{routing::get, Router, Server};
use axum::{
http::{self, StatusCode},
response,
routing::get,
Router, Server,
};
use log::{error, info};
use tokio::sync::Mutex;
@ -32,7 +37,7 @@ async fn main() -> Result<()> {
// Define routes
let message_routes = Router::new().route("/sms.aspx", get(get_sms_aspx));
let app = Router::new().merge(message_routes);
let app = Router::new().merge(message_routes).fallback(fallback);
info!("Server starting");
let addr: SocketAddr = match format!("0.0.0.0:{port:?}").parse() {
@ -59,9 +64,16 @@ async fn main() -> Result<()> {
Ok(())
}
///Handle server shutdown signal
async fn shutdown_signal() {
tokio::signal::ctrl_c()
.await
.expect("Expect shutdown signal handler");
info!("Got signal shutdown");
}
/// Response all fallback route with not found
pub async fn fallback(uri: http::Uri) -> impl response::IntoResponse {
info!("Route {} not found", uri);
(http::StatusCode::NOT_FOUND, "Not found")
}