1
0
mirror of https://github.com/actix/examples synced 2025-06-29 02:10:36 +02: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
2 changed files with 9 additions and 0 deletions

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)))
})