salvo-rs / salvo

A powerful web framework built with a simplified design.
https://salvo.rs
Apache License 2.0
3.26k stars 197 forks source link

静态文件服务用不了。按照文档上的写。没有use salvo::serve_static::StaticDir;中的serve_static没有 #886

Closed rongzhongyang closed 3 weeks ago

rongzhongyang commented 3 weeks ago

use salvo::prelude::*; use salvo::serve_static::StaticDir; //这行报错。没有serve_static

[tokio::main]

async fn main() { tracing_subscriber::fmt().init();

let router = Router::with_path("<**path>").get(
    StaticDir::new([
        "examples/static-dir-list/static/boy",
        "examples/static-dir-list/static/girl",
    ])
    .defaults("index.html")
    .auto_list(true),
);

let acceptor = TcpListener::new("127.0.0.1:5800").bind().await;
Server::new(acceptor).serve(router).await;

}

chrislearn commented 3 weeks ago

看这里,你需要打开对应的 feature 的。 https://github.com/salvo-rs/salvo/blob/main/examples/static-dir-list/Cargo.toml

salvo = { workspace = true, features=["serve-static"] }