mirror of
https://github.com/actix/examples
synced 2025-01-23 06:14:35 +01:00
add Cors to get juniper example to work. (#371)
This commit is contained in:
parent
95319754a1
commit
bcb02965d2
@ -6,6 +6,7 @@ edition = "2018"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = "3"
|
actix-web = "3"
|
||||||
|
actix-cors = "0.4.0"
|
||||||
env_logger = "0.7.1"
|
env_logger = "0.7.1"
|
||||||
serde = "1.0.103"
|
serde = "1.0.103"
|
||||||
serde_json = "1.0.44"
|
serde_json = "1.0.44"
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
use std::io;
|
use std::io;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use actix_cors::Cors;
|
||||||
use actix_web::{middleware, web, App, Error, HttpResponse, HttpServer};
|
use actix_web::{middleware, web, App, Error, HttpResponse, HttpServer};
|
||||||
use juniper::http::graphiql::graphiql_source;
|
use juniper::http::graphiql::graphiql_source;
|
||||||
use juniper::http::GraphQLRequest;
|
use juniper::http::GraphQLRequest;
|
||||||
@ -46,6 +47,13 @@ async fn main() -> io::Result<()> {
|
|||||||
App::new()
|
App::new()
|
||||||
.data(schema.clone())
|
.data(schema.clone())
|
||||||
.wrap(middleware::Logger::default())
|
.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("/graphql").route(web::post().to(graphql)))
|
||||||
.service(web::resource("/graphiql").route(web::get().to(graphiql)))
|
.service(web::resource("/graphiql").route(web::get().to(graphiql)))
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user