Actually parse address

This commit is contained in:
Hamcha 2020-01-24 16:51:05 +01:00
parent c33e305136
commit ab603643c9
Signed by: hamcha
GPG Key ID: 44AD3571EB09A39E
2 changed files with 15 additions and 5 deletions

View File

@ -248,18 +248,20 @@ impl Mutation {}
type Schema = juniper::RootNode<'static, Query, Mutation>;
pub fn server(databases: Vec<DBLog>) {
pub fn server(bind: &str, port: u16, databases: Vec<DBLog>) {
let schema = Schema::new(Query, Mutation);
let state = warp::any().map(move || Context {
databases: databases.clone().into_iter().map(from_db).collect(),
});
let graphql_filter = juniper_warp::make_graphql_filter(schema, state.boxed());
println!("Starting server at {}:{}\n\nEndpoints:\n graphql: http://{}:{}/graphql\n graphiql: http://{}:{}/graphiql", bind, port, bind, port, bind, port);
warp::serve(
warp::get2()
.and(warp::path("graphiql"))
.and(juniper_warp::graphiql_filter("/graphql"))
.or(warp::path("graphql").and(graphql_filter)),
)
.run(([127, 0, 0, 1], 8080));
.run(std::net::SocketAddr::new(bind.parse().unwrap(), port));
}

View File

@ -21,14 +21,22 @@ fn main() -> std::io::Result<()> {
.required(true)
.short("b")
.help("Address to bind to")
.default_value("127.0.0.1:9743")
.index(2),
.default_value("127.0.0.1"),
)
.arg(
Arg::with_name("port")
.required(true)
.short("p")
.help("Port to listen on")
.default_value("8080"),
)
.get_matches();
let basedir = cmd.value_of("basedir").unwrap();
let addr = cmd.value_of("bind").unwrap();
let port = cmd.value_of("port").unwrap().parse().unwrap();
let logs = scan_dbs(basedir);
println!("Loaded data for {} workspaces", logs.len());
server(logs);
server(addr, port, logs);
Ok(())
}