26 lines
774 B
Rust
26 lines
774 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)]
|
|
struct Config {
|
|
name: String,
|
|
description: String,
|
|
hostname: String,
|
|
port: u16
|
|
}
|
|
|
|
|
|
pub async fn server_meta(response: &mut Response<Body>) {
|
|
let payload = Config {
|
|
name: var("SERVER_NAME").unwrap_or("No name".into()),
|
|
description: var("SERVER_DESCRIPTION").unwrap_or("No description".into()),
|
|
hostname: var("SERVER_HOSTNAME").expect("Couldn't get url from environment"),
|
|
port: var("SERVER_PORT").expect("Couldn't get port from environment").parse::<u16>().unwrap(),
|
|
};
|
|
*response.body_mut() = Body::from(to_string(&payload).unwrap());
|
|
}
|