如何将根路径与扭曲过滤器匹配? [英] How can I match the root path with a Warp filter?
问题描述
我有一个使用Warp的简单Web服务器,该服务器提供静态文件.我遵循了Warp文档中的示例以获取以下信息:
让index_html = warp :: path(" index.html").map(handlers :: index_html);//回复在`handlers ::`中处理让script_js = warp :: path("script.js").map(handlers :: script_js);让路由= 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
的代码将替换为:
让index_html = warp :: path :: end().map(...);
I have a simple web server using Warp that serves static files. I followed the examples in the Warp docs to get the following:
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;
This returns files when requested from localhost:8000/index.html
and localhost:8000/script.js
.
I want to serve the index file from localhost:8000
rather than /index.html
, but I'm not sure how to specify the domain root with warp::path
. I've tried replacing warp::path("index.html")
with
warp::path()
warp::path("")
warp::path("/")
but with no success.
To target the root path use warp::path::end()
. The docs have an ambiguously brief description.
For the example above the code for index_html
would be replaced with:
let index_html = warp::path::end().map( ... );
这篇关于如何将根路径与扭曲过滤器匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!