Browse Source

Actually parse address

master
Hamcha 2 years ago
parent
commit
ab603643c9
Signed by: Hamcha GPG Key ID: 44AD3571EB09A39E
  1. 6
      backend/graphql.rs
  2. 14
      backend/main.rs

6
backend/graphql.rs

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

14
backend/main.rs

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

Loading…
Cancel
Save