2个稳定版本
1.2.0 | 2022年8月10日 |
---|---|
1.1.0 |
|
1.0.0 | 2022年8月9日 |
1400 在 HTTP服务器
7KB
71 行
warp_subdomain
一个用于Warp Web服务器框架的简单子域名解析中间件,处理时间以纳秒计算。🚀🚀
用法
... warp route
.and(warp_subdomain::with_subdomain)`
... route handler
示例
use std::collections::HashMap;
use std::sync::Arc;
use warp::Filter;
use warp_subdomain::with_subdomain;
async fn query(
_query: HashMap<String, String>,
subdomain: Arc<Vec<String>>,
) -> Result<impl warp::Reply, warp::Rejection> {
// get last subdomain
let subdomain_0 = subdomain.get(0);
Ok(warp::reply::with_status(
subdomain_0.unwrap().to_string(),
warp::http::StatusCode::FOUND,
))
}
#[tokio::main]
async fn main() {
let route = warp::path!("home")
.and(warp::get())
.and(warp::query::<HashMap<String, String>>())
.and(with_subdomain())
.and_then(query);
warp::serve(route).run(([127, 0, 0, 1], 3030)).await
}
/// If host eg. super-alloy.api.cilen.com.
/// This middleware will return
vec!["super-alloy", "api"]
/// This middleware also works for localhost that have port in host header.
/// eg. api.localhost:3999
注意
此中间件将返回类型为 Arc<Vec<String>>
其他
依赖项
~8–19MB
~247K SLoC