添加了新的log提示
This commit is contained in:
12
src/main.rs
12
src/main.rs
@@ -569,6 +569,9 @@ async fn serve_static_files(path: web::Path<String>) -> impl Responder {
|
||||
// 获取请求的文件路径(例如 "css/style.css")
|
||||
let file_path = path.into_inner();
|
||||
|
||||
// 【调试日志 1】打印服务器收到的文件路径
|
||||
info!("请求静态文件: {}", file_path);
|
||||
|
||||
// 从嵌入的 STATIC_DIR 中查找文件
|
||||
match STATIC_DIR.get_file(&file_path) {
|
||||
Some(file) => {
|
||||
@@ -577,16 +580,21 @@ async fn serve_static_files(path: web::Path<String>) -> impl Responder {
|
||||
Some("css") => "text/css",
|
||||
Some("js") => "application/javascript",
|
||||
Some("html") => "text/html",
|
||||
Some("ttf") | Some("woff") | Some("woff2") => "font/woff2", // 字体文件
|
||||
_ => "application/octet-stream", // 默认类型
|
||||
Some("ttf") => "font/ttf",
|
||||
Some("woff") => "font/woff",
|
||||
Some("woff2") => "font/woff2",
|
||||
_ => "application/octet-stream", // 默认类型
|
||||
};
|
||||
|
||||
info!("成功找到文件: {}, Content-Type: {}", file_path, content_type);
|
||||
HttpResponse::Ok()
|
||||
.content_type(content_type)
|
||||
.body(file.contents())
|
||||
}
|
||||
None => {
|
||||
// 文件不存在时返回 404
|
||||
// 【调试日志 3】打印文件未找到的信息
|
||||
info!("文件未找到: {}", file_path);
|
||||
HttpResponse::NotFound().body("静态文件不存在")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user