Serve favicon on /favicon.ico
This commit is contained in:
@@ -2,8 +2,10 @@ use dioxus::{
|
|||||||
fullstack::axum::{Router, middleware::from_fn},
|
fullstack::axum::{Router, middleware::from_fn},
|
||||||
server::axum::Extension,
|
server::axum::Extension,
|
||||||
};
|
};
|
||||||
|
use tower_http::services::ServeFile;
|
||||||
|
|
||||||
use crate::App;
|
use crate::App;
|
||||||
|
use crate::app::LOGO_ICO;
|
||||||
use crate::server::{
|
use crate::server::{
|
||||||
auth::build_auth_layer,
|
auth::build_auth_layer,
|
||||||
config::{self, Config},
|
config::{self, Config},
|
||||||
@@ -47,13 +49,28 @@ async fn router_setup(config: Config) -> Result<Router> {
|
|||||||
.await
|
.await
|
||||||
.err_context("Failed key-value store setup")?;
|
.err_context("Failed key-value store setup")?;
|
||||||
|
|
||||||
|
let favicon_path = {
|
||||||
|
// Resolve the favicon path
|
||||||
|
let asset_path = LOGO_ICO.resolve();
|
||||||
|
|
||||||
|
// If the asset path starts with "/", strip it. Otherwise it behaves as an "absolute path"
|
||||||
|
// and replaces the base path in the join operation. This is necessary because Dioxus will
|
||||||
|
// produce a path like "/assets/" in the call to `resolve`
|
||||||
|
let asset_path_rel = asset_path.strip_prefix("/").unwrap_or(&asset_path);
|
||||||
|
|
||||||
|
config.server.public_path.join(asset_path_rel)
|
||||||
|
};
|
||||||
|
|
||||||
|
tracing::debug!("Favicon path: {}", favicon_path.display());
|
||||||
|
|
||||||
let auth_layer = build_auth_layer(db_pool.clone(), key_val_pool, config.auth.cookies_secure);
|
let auth_layer = build_auth_layer(db_pool.clone(), key_val_pool, config.auth.cookies_secure);
|
||||||
|
|
||||||
let router = dioxus::server::router(App)
|
let router = dioxus::server::router(App)
|
||||||
.layer(from_fn(require_auth_middleware))
|
.layer(from_fn(require_auth_middleware))
|
||||||
.layer(Extension(config))
|
.layer(Extension(config))
|
||||||
.layer(Extension(db_pool))
|
.layer(Extension(db_pool))
|
||||||
.layer(auth_layer);
|
.layer(auth_layer)
|
||||||
|
.nest_service("/favicon.ico", ServeFile::new(favicon_path));
|
||||||
|
|
||||||
tracing::info!("Setup complete, returning Router...");
|
tracing::info!("Setup complete, returning Router...");
|
||||||
Ok(router)
|
Ok(router)
|
||||||
|
|||||||
Reference in New Issue
Block a user