This commit is contained in:
Dominic Grimm 2023-02-22 18:02:10 +01:00
parent 027aad58f9
commit 7f3cf3b2b5
No known key found for this signature in database
GPG key ID: 6F294212DEAAC530
11 changed files with 55 additions and 710 deletions

View file

@ -6,21 +6,7 @@ use tikv_jemallocator::Jemalloc;
static GLOBAL: Jemalloc = Jemalloc;
use actix_cors::Cors;
use actix_web::{
http::header,
middleware,
web::{self, Data},
App, Error, HttpResponse, HttpServer,
};
use juniper_actix::graphql_handler;
async fn graphql_route(
req: actix_web::HttpRequest,
payload: actix_web::web::Payload,
schema: web::Data<backend::graphql::Schema>,
) -> Result<HttpResponse, Error> {
graphql_handler(&schema, &backend::graphql::Context, req, payload).await
}
use actix_web::{http::header, middleware, App, HttpServer};
#[actix_web::main]
async fn main() -> std::io::Result<()> {
@ -29,23 +15,17 @@ async fn main() -> std::io::Result<()> {
let server = HttpServer::new(move || {
App::new()
.app_data(Data::new(backend::graphql::schema()))
.wrap(
Cors::default()
.allow_any_origin()
.allowed_methods(vec!["POST", "GET"])
.allowed_headers(vec![header::AUTHORIZATION, header::ACCEPT])
.allowed_header(header::ACCEPT)
.allowed_header(header::CONTENT_TYPE)
.supports_credentials()
.max_age(3600),
)
.wrap(middleware::Compress::default())
.wrap(middleware::Logger::default())
.service(
web::resource("/graphql")
.route(web::post().to(graphql_route))
.route(web::get().to(graphql_route)),
)
});
server.bind("0.0.0.0:80").unwrap().run().await
}