fix salvo serving static files

This commit is contained in:
Evan Almloff committed 2023-04-02 18:13:27 -05:00
1 parent 7214130c40
commit 987a0d5532
1 file changed
+12 -5
+12 -5
View File
@@ -2,8 +2,9 @@ use std::{error::Error, sync::Arc};
use hyper::{http::HeaderValue, StatusCode}; use hyper::{http::HeaderValue, StatusCode};
use salvo::{ use salvo::{
async_trait, handler, serve_static::StaticDir, Depot, FlowCtrl, Handler, Request, Response, async_trait, handler,
Router, serve_static::{StaticDir, StaticFile},
Depot, FlowCtrl, Handler, Request, Response, Router,
}; };
use server_fn::{Payload, ServerFunctionRegistry}; use server_fn::{Payload, ServerFunctionRegistry};
use tokio::task::spawn_blocking; use tokio::task::spawn_blocking;
@@ -80,7 +81,6 @@ impl DioxusRouterExt for Router {
if path.ends_with("index.html") { if path.ends_with("index.html") {
continue; continue;
} }
let serve_dir = StaticDir::new([path.clone()]);
let route = path let route = path
.strip_prefix(&cfg.assets_path) .strip_prefix(&cfg.assets_path)
.unwrap() .unwrap()
@@ -92,8 +92,15 @@ impl DioxusRouterExt for Router {
}) })
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join("/"); .join("/");
let route = format!("/{}/<**path>", route); if path.is_file() {
self = self.push(Router::with_path(route).get(serve_dir)) let route = format!("/{}", route);
let serve_dir = StaticFile::new(path.clone());
self = self.push(Router::with_path(route).get(serve_dir))
} else {
let route = format!("/{}/<**path>", route);
let serve_dir = StaticDir::new([path.clone()]);
self = self.push(Router::with_path(route).get(serve_dir))
}
} }
self.connect_hot_reload() self.connect_hot_reload()