1
0
mirror of https://github.com/actix/examples synced 2025-01-22 22:05:57 +01:00

add Cors to get juniper example to work. (#371)

This commit is contained in:
kczimm 2020-09-27 15:05:17 -05:00 committed by GitHub
parent 95319754a1
commit bcb02965d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -6,6 +6,7 @@ edition = "2018"
[dependencies]
actix-web = "3"
actix-cors = "0.4.0"
env_logger = "0.7.1"
serde = "1.0.103"
serde_json = "1.0.44"

View File

@ -4,6 +4,7 @@
use std::io;
use std::sync::Arc;
use actix_cors::Cors;
use actix_web::{middleware, web, App, Error, HttpResponse, HttpServer};
use juniper::http::graphiql::graphiql_source;
use juniper::http::GraphQLRequest;
@ -46,6 +47,13 @@ async fn main() -> io::Result<()> {
App::new()
.data(schema.clone())
.wrap(middleware::Logger::default())
.wrap(
Cors::new()
.allowed_methods(vec!["POST", "GET"])
.supports_credentials()
.max_age(3600)
.finish(),
)
.service(web::resource("/graphql").route(web::post().to(graphql)))
.service(web::resource("/graphiql").route(web::get().to(graphiql)))
})