diff --git a/json-api/src/meta.rs b/json-api/src/meta.rs index b5df7d8..96f1d6e 100644 --- a/json-api/src/meta.rs +++ b/json-api/src/meta.rs @@ -1,15 +1,14 @@ // Basic handler for getting meta data about the server -use std::env::var; use std::collections::HashMap; use crate::http::set_json_body; use mysql_async::Pool; use hyper::{Response, Body, StatusCode}; -use serde_json::{json, to_string}; +use serde_json::{json, to_string, Result as JsonResult}; use serde::{Serialize, Deserialize}; use lazy_static::lazy_static; -#[derive(Debug, Serialize)] +#[derive(Debug, Deserialize, Serialize)] pub struct Config { pub name: String, pub description: String, @@ -22,20 +21,20 @@ lazy_static! { // NOTE: this object must be access by proxy through get_config() #[derive(Deserialize, Serialize)] static ref BASIC_CONFIG: Config = { - let tags = var("SERVER_TAGS").unwrap(); - let tags: Vec = match serde_json::from_str(tags.as_str()).expect("Unable to parse tags") { - Some(tags) => tags, - None => vec![] - }; + use std::fs::File; + use std::io::BufReader; + match File::open("config.json") { + Ok(file) => { + let reader = BufReader::new(file); + let rr: JsonResult = serde_json::from_reader(reader); + match rr { + Ok(meta) => meta, + Err(e) => panic!("{}", e) + } - let cfg = Config { - name: var("SERVER_NAME").unwrap_or("No name".into()), - description: var("SERVER_DESCRIPTION").unwrap_or("No description".into()), - url: var("PUBLIC_URL").unwrap(), - wsurl: var("PUBLIC_WS_URL").unwrap(), - tags - }; - cfg + }, + Err(e) => panic!("{}", e) + } }; } @@ -60,7 +59,7 @@ pub async fn server_meta(response: &mut Response) { pub async fn server_neighbors(p: &Pool, response: &mut Response) { // This method refers to what servers have been added as **related** by the admins // It returns a list of servers meta objects which converted to JSON - match db::Neighbor::get_all(p).await { + match db::neighbors::get_all(p).await { Ok(neighbors) => set_json_body(response, json!({"neighbors": neighbors})), Err(e) => { *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;