Sends pubkeys on request
This commit is contained in:
parent
ebfaf38837
commit
46cad0ddea
|
@ -10,6 +10,7 @@ use hyper::{
|
||||||
service::{make_service_fn, service_fn},
|
service::{make_service_fn, service_fn},
|
||||||
Body, Method, Request, Response, Server, StatusCode,
|
Body, Method, Request, Response, Server, StatusCode,
|
||||||
};
|
};
|
||||||
|
use std::fs;
|
||||||
use lox::bridge_table::BridgeLine;
|
use lox::bridge_table::BridgeLine;
|
||||||
use lox::{BridgeAuth, BridgeDb, OPENINV_LENGTH};
|
use lox::{BridgeAuth, BridgeDb, OPENINV_LENGTH};
|
||||||
use rand::RngCore;
|
use rand::RngCore;
|
||||||
|
@ -80,10 +81,10 @@ async fn handle(
|
||||||
// addr: SocketAddr,
|
// addr: SocketAddr,
|
||||||
req: Request<Body>,
|
req: Request<Body>,
|
||||||
) -> Result<Response<Body>, Infallible> {
|
) -> Result<Response<Body>, Infallible> {
|
||||||
|
|
||||||
|
println!("Reqs on {}, {}", req.method(), req.uri().path());
|
||||||
match (req.method(), req.uri().path()) {
|
match (req.method(), req.uri().path()) {
|
||||||
(&Method::GET, "/") | (&Method::GET, "/index.html") => {
|
(&Method::GET, "/invite") => Ok::<_, Infallible>(generate_invite(context.db)),
|
||||||
Ok::<_, Infallible>(generate_invite(context.db))
|
|
||||||
}
|
|
||||||
(&Method::GET, "/pubkeys") => Ok::<_, Infallible>(send_keys(&context.pubkey_filename)),
|
(&Method::GET, "/pubkeys") => Ok::<_, Infallible>(send_keys(&context.pubkey_filename)),
|
||||||
//(&Method::POST, "/json_api") => api_post_response(req).await,
|
//(&Method::POST, "/json_api") => api_post_response(req).await,
|
||||||
//(&Method::GET, "/json_api") => api_get_response().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> {
|
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));
|
let mut resp = Response::new(Body::from(json_keys));
|
||||||
resp.headers_mut()
|
resp.headers_mut()
|
||||||
.insert("Content-Type", HeaderValue::from_static("application/json"));
|
.insert("Access-Control-Allow-Origin", HeaderValue::from_static("*"));
|
||||||
resp
|
resp
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue