I've used the Warp example in the docs to create a graphql application. That said, I am trying to now serve a react spa directory, but is running into issues.
It seems that anything after the "graphql_post" route from the example, does not work at all, making it impossible to serve the static files on fall through cases.
How would i use this example but end it with or(other) without it giving this error:
let graphql_post = warp::header::optional::<String>("auth")
.and(async_graphql_warp::graphql(schema.clone()))
.and_then(
|token,
(schema, mut request): (
Schema<QueryRoot, MutationRoot, SubscriptionRoot>,
async_graphql::Request,
)| async move {
if let Some(token) = token {
request = request.data(MyToken(token));
}
let resp = schema.execute(request).await;
Ok::<_, Infallible>(Response::from(resp))
},
);
let graphql_playground = warp::path("api").and(warp::get()).map(|| {
HttpResponse::builder()
.header("content-type", "text/html")
.body(playground_source(
GraphQLPlaygroundConfig::new("/api").subscription_endpoint("/api"),
))
});
let app_modeling_out_csv = warp::path("app_modeling.csv")
.and(warp::get())
.and(with_db(database_connections.0.clone()))
.and_then(out_csv_app_modeling);
let db_modeling_out_csv = warp::path("db_modeling.csv")
.and(warp::get())
.and(with_db(database_connections.0.clone()))
.and_then(out_csv_db_modeling);
let cors = warp::cors()
.allow_any_origin()
.allow_headers(vec![
"auth",
"accept",
"sec-ch-ua",
"sec-ch-ua-mobile",
"User-Agent",
"Sec-Fetch-Mode",
"Referer",
"Origin",
"Access-Control-Request-Method",
"Access-Control-Request-Headers",
"content-type",
])
.allow_methods(vec!["OPTIONS", "GET", "POST", "DELETE", "PUT"]);
let react_app = warp::fs::dir("build");
// let other = warp::path::end().and(warp::fs::dir("build"));
let other = warp::fs::file("build/index.html");
let warp_log = warp::log("info");
let routes = react_app
.or(graphql_subscription(schema))
.or(app_modeling_out_csv)
.or(db_modeling_out_csv)
.or(graphql_playground)
.or(graphql_post)
.or(other) // THIS DOES NOT GET READ, if i put it above graphql post, it works, but graphql post does not.
.recover(recover_api)
.with(cors)
.with(warp_log);
warp::serve(routes)
.run(([0, 0, 0, 0], 5000))
.await;
Hey guys,
I've used the Warp example in the docs to create a graphql application. That said, I am trying to now serve a react spa directory, but is running into issues.
It seems that anything after the "graphql_post" route from the example, does not work at all, making it impossible to serve the static files on fall through cases.
How would i use this example but end it with or(other) without it giving this error: