Replies: 3 comments 1 reply
-
It looks like what you need is let app = Route::new()
.at("/graphql", post(routes::graphql_handler))
.nest("/other-service", post(routes::route_to_other_service))
.data(schema); |
Beta Was this translation helpful? Give feedback.
0 replies
-
I choose to go with // main.rs
let app = Route::new()
.at("/", get(routes::graphql_playground))
.at("/graphql", post(routes::graphql_handler))
.at("/other/*path", get(routes::other).post(routes::other))
.data(schema)
.data(Arc::clone(&server_context)); // routes.rs
#[handler]
pub async fn graphql_handler(schema: Data<&AppSchema>, req: Json<Request>) -> Json<Response> {
Json(schema.execute(req.0).await)
}
#[handler]
pub async fn risetai(
ctx: Data<Arc<ServerContext>>,
Path(path): Path<String>,
body: Json<Value>,
headers: &HeaderMap,
) -> String {
ctx.other_service.route(path, body, headers).await
} However, I got an error: error[E0277]: the trait bound `poem::web::Data<Arc<ServerContext>>: FromRequest<'_>` is not satisfied
--> src/routes.rs:26:1
|
26 | #[handler]
| ^^^^^^^^^^ the trait `FromRequest<'_>` is not implemented for `poem::web::Data<Arc<ServerContext>>`
|
= help: the following implementations were found:
<poem::web::Data<&'a T> as FromRequest<'a>>
= note: this error originates in the attribute macro `handler` (in Nightly builds, run with -Z macro-backtrace for more info)
For more information about this error, try `rustc --explain E0277`.
error: could not compile `app` due to previous error I think it is doable in actix-web Is using |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
azzamsa
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a web app act as both auth server and middleware to route to other service.
/graphql
endpoint (graphql output)/other-service-endpoint/feature
(json output)Without the first step, my app is simply:
Now, I want to be able for every user accessing
/other-service-endpoint/foo
or/other-service-endpoint/bar
to route them intoother-service-ip/foo
andother-service-ip/bar
respectively`I was thinking this is suitable for middleware, but I go with most easiest path. Instead of using
/other-service-endpoint/bar
as url. I ask client to acces/other-service-endpoint/
and setbar
in header request.How to create mutiple route for this?
Something like?
Or, do you have any better approach?
Thanks for Poem.
Beta Was this translation helpful? Give feedback.
All reactions