Skip to content

Commit 60798cf

Browse files
committed
feat(host): accept customized host point
1 parent eb91ee5 commit 60798cf

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/main.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use async_graphql::{EmptyMutation, EmptySubscription, Schema};
55
use async_graphql_warp::Response;
66
use dotenv::dotenv;
77
use log::debug;
8+
use std::net::SocketAddr;
89
use std::{convert::Infallible, path::Path};
910
use structopt::StructOpt;
1011
use warp::{http::Response as HttpResponse, Filter};
@@ -33,7 +34,7 @@ async fn main() {
3334
let config = Configuration::from_file(opt.config).await;
3435
debug!("{:?}", config);
3536

36-
print!("Playground: http://localhost:8000/playground");
37+
println!("Playground: http://{}/playground", opt.access_point);
3738

3839
let schema = Schema::build(Query, EmptyMutation, EmptySubscription)
3940
.data(config.clone())
@@ -63,5 +64,6 @@ async fn main() {
6364

6465
let routes = graphql_playground.or(graphql_post).or(static_files).or(fallback);
6566

66-
warp::serve(routes).run(([0, 0, 0, 0], 8000)).await;
67+
let socket_addr: SocketAddr = opt.access_point.parse().expect("Unable to parse host address");
68+
warp::serve(routes).run(socket_addr).await;
6769
}

src/opts.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ pub struct Opt {
1313
pub log_level: u32,
1414

1515
/// configuration file's, check example for more details
16-
#[structopt(default_value = "config.ron", env = "CONFIG", parse(from_os_str))]
16+
#[structopt(short, long, default_value = "config.ron", env = "CONFIG", parse(from_os_str))]
1717
pub config: PathBuf,
1818

1919
/// static file path to be serve
20-
#[structopt(short = "s", long = "static", env = "STATIC")]
20+
#[structopt(short, long = "static", env = "STATIC")]
2121
pub static_file_path: String,
22+
23+
/// serve host
24+
#[structopt(short, long, default_value = "0.0.0.0:8000")]
25+
pub access_point: String,
2226
}

0 commit comments

Comments
 (0)