config issues are being ignored for now there are bigger things to deal with
This commit is contained in:
parent
e0ede8d96b
commit
a3519e32a6
@ -6,6 +6,7 @@
|
|||||||
extern crate rocket_contrib;
|
extern crate rocket_contrib;
|
||||||
|
|
||||||
|
|
||||||
|
use dotenv;
|
||||||
use rocket_contrib::serve::StaticFiles;
|
use rocket_contrib::serve::StaticFiles;
|
||||||
use rocket_contrib::templates::Template;
|
use rocket_contrib::templates::Template;
|
||||||
|
|
||||||
|
@ -2,54 +2,23 @@
|
|||||||
// All new servers come with this as a default so that
|
// All new servers come with this as a default so that
|
||||||
use rocket_contrib::templates::Template;
|
use rocket_contrib::templates::Template;
|
||||||
use rocket::response::NamedFile;
|
use rocket::response::NamedFile;
|
||||||
|
use dotenv;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::fs::read_to_string;
|
|
||||||
use serde_derive::Deserialize;
|
use serde_derive::Deserialize;
|
||||||
|
|
||||||
// Purely for backend purposes
|
// Purely for backend purposes
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct WebsiteConfig {
|
pub struct WebsiteConfig {
|
||||||
url: Option<String>, // default is freechat.io - clean url of domain
|
|
||||||
favicon: Option<String>, // uri path to the favicon i.e. /media/static/favicon.png
|
|
||||||
motto: Option<String>,
|
|
||||||
title: Option<String>,
|
|
||||||
description: Option<String>,
|
|
||||||
og_type: Option<String>,
|
|
||||||
stylesheet: String,
|
stylesheet: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init() {
|
pub fn init() {
|
||||||
// Default values which are later overriden
|
|
||||||
env::set_var("web_url", "freechat.io");
|
|
||||||
env::set_var("web_favicon", "/static/images/favicon.png");
|
|
||||||
env::set_var("web_motto", "Decentralized free chat platform");
|
|
||||||
env::set_var("web_title", "Freechat");
|
|
||||||
env::set_var("web_og_type", "Decentralized Chat Platform");
|
|
||||||
|
|
||||||
|
|
||||||
// If there's a problem we're going to panic and that's fine to be completely honest
|
|
||||||
if let Ok(file) = read_to_string("configs/website.toml") {
|
|
||||||
let config: WebsiteConfig = toml::from_str(&file).unwrap();
|
|
||||||
println!("file contents: {:?}", config);
|
|
||||||
env::set_var("web_url", config.url.unwrap());
|
|
||||||
env::set_var("web_favicon", config.favicon.unwrap());
|
|
||||||
env::set_var("web_motto", config.motto.unwrap());
|
|
||||||
env::set_var("web_title", config.title.unwrap());
|
|
||||||
env::set_var("web_og_type", config.og_type.unwrap());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
pub fn homepage() -> Template {
|
pub fn homepage() -> Template {
|
||||||
// look away
|
|
||||||
Template::render("index", WebsiteConfig {
|
Template::render("index", WebsiteConfig {
|
||||||
url: Some(env::var("web_url").unwrap()),
|
|
||||||
favicon: Some(env::var("web_favicon").unwrap()),
|
|
||||||
motto: Some(env::var("web_motto").unwrap()),
|
|
||||||
title: Some(env::var("web_title").unwrap()),
|
|
||||||
description: Some(env::var("web_description").unwrap()),
|
|
||||||
og_type: Some(env::var("web_og_type").unwrap()),
|
|
||||||
stylesheet: "/static/css/index.css".to_string()
|
stylesheet: "/static/css/index.css".to_string()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -57,12 +26,6 @@ pub fn homepage() -> Template {
|
|||||||
#[get("/about")]
|
#[get("/about")]
|
||||||
pub fn about_page() -> Template {
|
pub fn about_page() -> Template {
|
||||||
Template::render("about", WebsiteConfig {
|
Template::render("about", WebsiteConfig {
|
||||||
url: Some(env::var("web_url").unwrap()),
|
|
||||||
favicon: Some(env::var("web_favicon").unwrap()),
|
|
||||||
motto: Some(env::var("web_motto").unwrap()),
|
|
||||||
title: Some(env::var("web_title").unwrap()),
|
|
||||||
description: Some(env::var("web_description").unwrap()),
|
|
||||||
og_type: Some(env::var("web_og_type").unwrap()),
|
|
||||||
stylesheet: "/static/css/about.css".to_string()
|
stylesheet: "/static/css/about.css".to_string()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -70,12 +33,6 @@ pub fn about_page() -> Template {
|
|||||||
#[get("/servers")]
|
#[get("/servers")]
|
||||||
pub fn server_info() -> Template {
|
pub fn server_info() -> Template {
|
||||||
Template::render("servers", WebsiteConfig {
|
Template::render("servers", WebsiteConfig {
|
||||||
url: Some(env::var("web_url").unwrap()),
|
|
||||||
favicon: Some(env::var("web_favicon").unwrap()),
|
|
||||||
motto: Some(env::var("web_motto").unwrap()),
|
|
||||||
title: Some(env::var("web_title").unwrap()),
|
|
||||||
description: Some(env::var("web_description").unwrap()),
|
|
||||||
og_type: Some(env::var("web_og_type").unwrap()),
|
|
||||||
stylesheet: "/static/css/about.css".to_string()
|
stylesheet: "/static/css/about.css".to_string()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user