-
Feature RequestWhen I use wildcards for axum Router, the Here is an example reference: #[tokio::main]
async fn main() {
init_http_proxy().await;
}
pub async fn init_http_proxy() {
let service = tower::service_fn(handle);
let app = Router::new().route("/*path", any_service(service));
axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
.serve(app.into_make_service())
.await
.unwrap();
}
async fn handle(req: Request<Body>) -> Result<Response<Body>, Infallible> {
+ let uri = req.uri();
...
} Now known way, get it through async fn handle(
+ path:Path<String>,
req: Request<Body>) -> Result<Response<Body>, Infallible> {
...
}
|
Beta Was this translation helpful? Give feedback.
Answered by
baoyachi
May 6, 2023
Replies: 2 comments 1 reply
-
You can extract |
Beta Was this translation helpful? Give feedback.
0 replies
-
Sorry, I solved this problem by reading the document. The detail code: #[tokio::main]
async fn main() {
init_http_proxy().await;
}
pub async fn init_http_proxy() {
+ let app = Router::new().route("/*path", on(MethodFilter::all(),handle));
axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
.serve(app.into_make_service())
.await
.unwrap();
}
async fn handle(
+ path:Path<String>,
req: Request<Body>) -> Result<Response<Body>, Infallible> {
...
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use
on()
method to replaceany_ service()
method