Skip to content

Commit

Permalink
fix: breaking: Router::fallback now only accepts Handlers (similarly …
Browse files Browse the repository at this point in the history
…to what get, post, etc accept). Use the new Router::fallback_service for setting any Service as the fallback (#1155)

Refs: tokio-rs/axum#1155
  • Loading branch information
ttys3 committed Aug 22, 2022
1 parent 46310ba commit 98ae7ba
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 55 deletions.
103 changes: 51 additions & 52 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use axum_macros::debug_handler;
use std::{net::SocketAddr, sync::Arc};
use tower_http::trace::TraceLayer;

// use axum::{extract::Path as extractPath};

use crate::ResponseError::{BadRequest, FileNotFound, InternalError};
use askama::Template;

Expand All @@ -30,6 +28,7 @@ use clap::Parser;
use axum::extract::ConnectInfo;
use percent_encoding::percent_decode;
use std::str::FromStr;
use axum::handler::HandlerWithoutStateExt;

#[derive(Parser, Debug)]
#[clap(name = "static-server", about = "A simple static file server written in Rust based on axum framework.")]
Expand Down Expand Up @@ -80,7 +79,7 @@ async fn main() {
let app = Router::new()
.route("/favicon.ico", get(favicon))
.route("/healthz", get(health_check))
.fallback(get(index_or_content))
.fallback_service(index_or_content.into_service())
.layer(Extension(Arc::new(StaticServerConfig { root_dir })))
.layer(TraceLayer::new_for_http().make_span_with(|request: &Request<Body>| {
let ConnectInfo(addr) = request.extensions().get::<ConnectInfo<SocketAddr>>().unwrap();
Expand Down

0 comments on commit 98ae7ba

Please sign in to comment.