diff --git a/crates/lox-distributor/src/main.rs b/crates/lox-distributor/src/main.rs index ccf4c21..aa5772c 100644 --- a/crates/lox-distributor/src/main.rs +++ b/crates/lox-distributor/src/main.rs @@ -10,6 +10,7 @@ use hyper::{ service::{make_service_fn, service_fn}, Body, Method, Request, Response, Server, StatusCode, }; +use std::fs; use lox::bridge_table::BridgeLine; use lox::{BridgeAuth, BridgeDb, OPENINV_LENGTH}; use rand::RngCore; @@ -80,10 +81,10 @@ async fn handle( // addr: SocketAddr, req: Request, ) -> Result, Infallible> { + + println!("Reqs on {}, {}", req.method(), req.uri().path()); match (req.method(), req.uri().path()) { - (&Method::GET, "/") | (&Method::GET, "/index.html") => { - Ok::<_, Infallible>(generate_invite(context.db)) - } + (&Method::GET, "/invite") => Ok::<_, Infallible>(generate_invite(context.db)), (&Method::GET, "/pubkeys") => Ok::<_, Infallible>(send_keys(&context.pubkey_filename)), //(&Method::POST, "/json_api") => api_post_response(req).await, //(&Method::GET, "/json_api") => api_get_response().await, @@ -179,9 +180,10 @@ fn generate_invite(db: Arc>) -> Response { } fn send_keys(pubkeys_filename: &str) -> Response { - let json_keys = serde_json::to_string(pubkeys_filename).expect("JSON was not well-formatted"); + let data = fs::read_to_string(pubkeys_filename).expect("Unable to read file"); + let json_keys = serde_json::to_string(&data).expect("JSON was not well-formatted"); let mut resp = Response::new(Body::from(json_keys)); resp.headers_mut() - .insert("Content-Type", HeaderValue::from_static("application/json")); + .insert("Access-Control-Allow-Origin", HeaderValue::from_static("*")); resp }