feat(conf): add config param playground_path

This commit is contained in:
librelois 2021-05-30 00:22:13 +02:00
parent 3d9e3ffe49
commit d2c46fbd06
2 changed files with 19 additions and 14 deletions

View file

@ -34,6 +34,8 @@ pub struct GvaConf {
pub port: u16, pub port: u16,
#[serde(default = "path_default")] #[serde(default = "path_default")]
pub path: String, pub path: String,
#[serde(default = "playground_path_default")]
pub playground_path: String,
#[serde(default = "subscriptions_path_default")] #[serde(default = "subscriptions_path_default")]
pub subscriptions_path: String, pub subscriptions_path: String,
pub remote_host: Option<String>, pub remote_host: Option<String>,
@ -57,6 +59,10 @@ fn path_default() -> String {
"gva".to_owned() "gva".to_owned()
} }
fn playground_path_default() -> String {
"gva-playground".to_owned()
}
const fn port_default() -> u16 { const fn port_default() -> u16 {
30_901 30_901
} }
@ -79,6 +85,7 @@ impl Default for GvaConf {
ip4: ip4_default(), ip4: ip4_default(),
ip6: Some(ip6_default()), ip6: Some(ip6_default()),
port: port_default(), port: port_default(),
playground_path: playground_path_default(),
path: path_default(), path: path_default(),
subscriptions_path: subscriptions_path_default(), subscriptions_path: subscriptions_path_default(),
remote_host: None, remote_host: None,

View file

@ -277,20 +277,18 @@ impl GvaModule {
); );
let conf_clone = conf.clone(); let conf_clone = conf.clone();
let graphql_playground = let graphql_playground = warp::path::path(conf.playground_path.clone())
warp::path::path(conf.path.clone()) .and(warp::get())
.and(warp::get()) .map(move || {
.map(move || { HttpResponse::builder()
HttpResponse::builder() .header("content-type", "text/html")
.header("content-type", "text/html") .body(async_graphql::http::playground_source(
.body(async_graphql::http::playground_source( GraphQLPlaygroundConfig::new(&format!("/{}", &conf_clone.path))
GraphQLPlaygroundConfig::new(&format!("/{}", &conf_clone.path)) .subscription_endpoint(
.subscription_endpoint(&format!( &format!("/{}", &conf_clone.subscriptions_path,),
"/{}", ),
&conf_clone.subscriptions_path, ))
)), });
))
});
let routes = graphql_playground let routes = graphql_playground
.or(graphql_post) .or(graphql_post)