Filter 如何将根路径与扭曲过滤器匹配?
我有一个简单的web服务器,使用Warp提供静态文件。我按照Warp文档中的示例获得以下内容:Filter 如何将根路径与扭曲过滤器匹配?,filter,rust,Filter,Rust,我有一个简单的web服务器,使用Warp提供静态文件。我按照Warp文档中的示例获得以下内容: let index_html = warp::path("index.html").map(handlers::index_html); // reply is handled in `handlers::` let script_js = warp::path("script.js").map(handlers::script_js); let route
let index_html = warp::path("index.html").map(handlers::index_html); // reply is handled in `handlers::`
let script_js = warp::path("script.js").map(handlers::script_js);
let routes = warp::get().and(index_html.or(script_js));
warp::serve(routes).run(([127, 0, 0, 1], 8000)).await;
当从localhost:8000/index.html
和localhost:8000/script.js
请求文件时,将返回文件
我想从localhost:8000
而不是/index.html
提供索引文件,但我不确定如何使用warp::path
指定域根。我已经尝试将warp::path(“index.html”)
替换为
warp::path()
warp::path(“”)
warp::path(“/”)
但是没有成功。要以根路径为目标,请使用
warp::path::end()
。这本书的描述含糊不清
对于上面的示例,index_html
的代码将替换为:
let index_html = warp::path::end().map( ... );
要以根路径为目标,请使用
warp::path::end()
。这本书的描述含糊不清
对于上面的示例,index_html
的代码将替换为:
let index_html = warp::path::end().map( ... );
另请参见
路径代码>宏,默认情况下添加end()
。然后您就可以使用path了!()
。另请参见路径代码>宏,默认情况下添加end()
。然后您就可以使用path了!()
。