feat: add static dir

This commit is contained in:
2021-04-07 00:30:53 +08:00
parent 6bc61da148
commit 521fc4f369
3 changed files with 552 additions and 1 deletions

View File

@@ -1,4 +1,5 @@
use salvo::prelude::*;
use salvo_extra::serve::StaticDir;
#[fn_handler]
async fn hello_world(req: &mut Request, _depot: &mut Depot, res: &mut Response) {
@@ -25,7 +26,10 @@ async fn main() {
Router::new().path("json").get(print_json)
).push(
Router::new().path("redirect").get(send_redirect)
).push(
Router::new().path("files/<**path>").get(StaticDir::new("target"))
);
let server = Server::new(router);
println!("Listen 0.0.0.0:7878...");
server.bind(([0, 0, 0, 0], 7878)).await;
}