freechat/json-api/src/meta.rs
shockrah 522890fa00 + rtc::new_message now takes a Pool ref to make the second call for the user name
! Start taking public user params like this in the JWT to reduce on network hits
It's cheap and reliable enough but the idea just now came to me so do that at some point
2021-04-14 22:46:31 -07:00

29 lines
715 B
Rust

// Basic handler for getting meta data about the server
use std::env::var;
use hyper::{Response, Body};
use serde_json::to_string;
use serde::Serialize;
#[derive( Serialize)]
pub struct Config {
pub name: String,
pub description: String,
pub url: String,
pub wsurl: String,
}
pub fn get_config() -> Config {
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()
}
}
pub async fn server_meta(response: &mut Response<Body>) {
*response.body_mut() = Body::from(to_string(&get_config()).unwrap());
}