我有一个使用 Warp 的简单 Web 服务器来提供静态文件。我按照 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 routes = warp::get().and(index_html.or(script_js));
warp::serve(routes).run(([127, 0, 0, 1], 8000)).await;
Run Code Online (Sandbox Code Playgroud)
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( ... );
Run Code Online (Sandbox Code Playgroud)