* Fixing some json serialization/parsing weirdness in the meta::BASIC_CONFIG initialization
This is part of a bigger change to stop using environment variables around as state as its mega cheese
This commit is contained in:
parent
adc5b261e8
commit
b3c27b86ce
@ -1,15 +1,14 @@
|
|||||||
// Basic handler for getting meta data about the server
|
// Basic handler for getting meta data about the server
|
||||||
use std::env::var;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use crate::http::set_json_body;
|
use crate::http::set_json_body;
|
||||||
|
|
||||||
use mysql_async::Pool;
|
use mysql_async::Pool;
|
||||||
use hyper::{Response, Body, StatusCode};
|
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 serde::{Serialize, Deserialize};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub description: String,
|
pub description: String,
|
||||||
@ -22,20 +21,20 @@ lazy_static! {
|
|||||||
// NOTE: this object must be access by proxy through get_config()
|
// NOTE: this object must be access by proxy through get_config()
|
||||||
#[derive(Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize)]
|
||||||
static ref BASIC_CONFIG: Config = {
|
static ref BASIC_CONFIG: Config = {
|
||||||
let tags = var("SERVER_TAGS").unwrap();
|
use std::fs::File;
|
||||||
let tags: Vec<String> = match serde_json::from_str(tags.as_str()).expect("Unable to parse tags") {
|
use std::io::BufReader;
|
||||||
Some(tags) => tags,
|
match File::open("config.json") {
|
||||||
None => vec![]
|
Ok(file) => {
|
||||||
};
|
let reader = BufReader::new(file);
|
||||||
|
let rr: JsonResult<Config> = 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()),
|
Err(e) => panic!("{}", e)
|
||||||
description: var("SERVER_DESCRIPTION").unwrap_or("No description".into()),
|
}
|
||||||
url: var("PUBLIC_URL").unwrap(),
|
|
||||||
wsurl: var("PUBLIC_WS_URL").unwrap(),
|
|
||||||
tags
|
|
||||||
};
|
|
||||||
cfg
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,7 +59,7 @@ pub async fn server_meta(response: &mut Response<Body>) {
|
|||||||
pub async fn server_neighbors(p: &Pool, response: &mut Response<Body>) {
|
pub async fn server_neighbors(p: &Pool, response: &mut Response<Body>) {
|
||||||
// This method refers to what servers have been added as **related** by the admins
|
// 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
|
// 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})),
|
Ok(neighbors) => set_json_body(response, json!({"neighbors": neighbors})),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
|
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
|
||||||
|
Loading…
Reference in New Issue
Block a user