gpt4 book ai didi

filter - 如何将根路径与扭曲过滤器匹配?

转载 作者:行者123 更新时间:2023-12-03 11:34:07 25 4
gpt4 key购买 nike

我有一个使用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;
当从 localhost:8000/index.htmllocalhost:8000/script.js请求时,这将返回文件。
我想从 localhost:8000而不是 /index.html提供索引文件,但是我不确定如何用 warp::path指定域根。我尝试用替换 warp::path("index.html")
  • warp::path()
  • warp::path("")
  • warp::path("/")

  • 但没有成功。

    最佳答案

    要定位根路径,请使用warp::path::end()docs的描述含糊不清。
    对于上面的示例,index_html的代码将替换为:

    let index_html = warp::path::end().map( ... );

    关于filter - 如何将根路径与扭曲过滤器匹配?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63003414/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com