mirror of
https://github.com/DefectingCat/rua-list
synced 2025-07-15 16:51:31 +00:00
Add fallback route
This commit is contained in:
16
src/main.rs
16
src/main.rs
@ -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")
|
||||
}
|
Reference in New Issue
Block a user