Try using axum instead of rocket. WS doesn't seem to work through trunk
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
// Rocket generates a lot of warnings for handlers
|
||||
// TODO: figure out why
|
||||
#![allow(unreachable_patterns)]
|
||||
#[macro_use]
|
||||
extern crate rocket;
|
||||
use std::{error::Error, io::Cursor, str::FromStr};
|
||||
|
||||
use async_graphql::{extensions, http::GraphiQLSource, EmptySubscription, Schema};
|
||||
use async_graphql_rocket::{GraphQLQuery, GraphQLRequest, GraphQLResponse};
|
||||
use async_graphql::{extensions, http::GraphiQLSource, Schema};
|
||||
use async_graphql_axum::{GraphQL, GraphQLSubscription};
|
||||
use axum::{
|
||||
response::{self, IntoResponse},
|
||||
routing::get,
|
||||
Router,
|
||||
};
|
||||
use cacher::FilesystemCacher;
|
||||
use letterbox_notmuch::{Notmuch, NotmuchError, ThreadSet};
|
||||
#[cfg(feature = "tantivy")]
|
||||
@@ -14,20 +17,14 @@ use letterbox_server::tantivy::TantivyConnection;
|
||||
use letterbox_server::{
|
||||
config::Config,
|
||||
error::ServerError,
|
||||
graphql::{Attachment, GraphqlSchema, Mutation, QueryRoot, Subscription},
|
||||
graphql::{Attachment, GraphqlSchema, MutationRoot, QueryRoot, SubscriptionRoot},
|
||||
nm::{attachment_bytes, cid_attachment_bytes},
|
||||
};
|
||||
use rocket::{
|
||||
fairing::AdHoc,
|
||||
http::{ContentType, Header},
|
||||
request::Request,
|
||||
response::{content, Debug, Responder},
|
||||
serde::json::Json,
|
||||
Response, State,
|
||||
};
|
||||
use rocket_cors::{AllowedHeaders, AllowedOrigins};
|
||||
use sqlx::postgres::PgPool;
|
||||
use tokio::net::TcpListener;
|
||||
use tower_http::trace::TraceLayer;
|
||||
|
||||
/*
|
||||
#[get("/show/<query>/pretty")]
|
||||
async fn show_pretty(
|
||||
nm: &State<Notmuch>,
|
||||
@@ -243,3 +240,41 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||
rkt.launch().await?;
|
||||
Ok(())
|
||||
}
|
||||
*/
|
||||
|
||||
async fn graphiql() -> impl IntoResponse {
|
||||
response::Html(
|
||||
GraphiQLSource::build()
|
||||
.endpoint("/api/")
|
||||
.subscription_endpoint("/api/ws")
|
||||
.finish(),
|
||||
)
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn Error>> {
|
||||
let _guard = xtracing::init(env!("CARGO_BIN_NAME"))?;
|
||||
let schema = Schema::build(QueryRoot, MutationRoot, SubscriptionRoot)
|
||||
//.data(Storage::default())
|
||||
.finish();
|
||||
|
||||
let app = Router::new()
|
||||
.route(
|
||||
"/api/",
|
||||
get(graphiql).post_service(GraphQL::new(schema.clone())),
|
||||
)
|
||||
.route_service("/api/ws", GraphQLSubscription::new(schema))
|
||||
.layer(
|
||||
TraceLayer::new_for_http()
|
||||
.on_request(tower_http::trace::DefaultOnRequest::new().level(tracing::Level::INFO))
|
||||
.on_response(
|
||||
tower_http::trace::DefaultOnResponse::new().level(tracing::Level::INFO),
|
||||
)
|
||||
.on_failure(tower_http::trace::DefaultOnFailure::new().level(tracing::Level::WARN)),
|
||||
);
|
||||
|
||||
axum::serve(TcpListener::bind("0.0.0.0:9345").await.unwrap(), app)
|
||||
.await
|
||||
.unwrap();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user