Sends pubkeys on request
This commit is contained in:
parent
0f0f13df0d
commit
61940bdfe3
|
@ -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<Body>,
|
||||
) -> Result<Response<Body>, 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<Mutex<lox::BridgeDb>>) -> Response<Body> {
|
|||
}
|
||||
|
||||
fn send_keys(pubkeys_filename: &str) -> Response<Body> {
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue