Add hostname to Rocket.toml config

next
timokoesters 2020-04-29 08:48:56 +02:00
parent 23cb550d00
commit 1cdf30f38c
No known key found for this signature in database
GPG Key ID: 24DA7517711A2BA4
2 changed files with 11 additions and 8 deletions

View File

@ -1,6 +1,7 @@
[global] [global]
address = "0.0.0.0" hostname = "conduit.rs"
port = 14004 port = 14004
address = "0.0.0.0"
[global.tls] [global.tls]
certs = "/etc/letsencrypt/live/matrixtesting.koesters.xyz/fullchain.pem" certs = "/etc/letsencrypt/live/matrixtesting.koesters.xyz/fullchain.pem"

View File

@ -16,9 +16,9 @@ pub use database::Database;
pub use pdu::PduEvent; pub use pdu::PduEvent;
pub use ruma_wrapper::{MatrixResult, Ruma}; pub use ruma_wrapper::{MatrixResult, Ruma};
use rocket::routes; use rocket::{fairing::AdHoc, routes};
fn setup_rocket(data: Data) -> rocket::Rocket { fn setup_rocket() -> rocket::Rocket {
rocket::ignite() rocket::ignite()
.mount( .mount(
"/", "/",
@ -68,7 +68,12 @@ fn setup_rocket(data: Data) -> rocket::Rocket {
server_server::get_server_keys_deprecated, server_server::get_server_keys_deprecated,
], ],
) )
.manage(data) .attach(AdHoc::on_attach("Config", |rocket| {
let hostname = rocket.config().get_str("hostname").unwrap_or("localhost");
let data = Data::load_or_create(&hostname);
Ok(rocket.manage(data))
}))
} }
fn main() { fn main() {
@ -78,8 +83,5 @@ fn main() {
} }
pretty_env_logger::init(); pretty_env_logger::init();
let data = Data::load_or_create("conduit.rs"); setup_rocket().launch().unwrap();
//data.debug();
setup_rocket(data).launch().unwrap();
} }