Added correct config reading

pull/3/head
Jef Roosens 2021-11-23 18:00:10 +01:00
parent b99d9faa04
commit 6013d0bb6e
Signed by: Jef Roosens
GPG Key ID: 955C0660072F691F
3 changed files with 51 additions and 12 deletions

41
Rb.yaml 100644
View File

@ -0,0 +1,41 @@
default:
address: "0.0.0.0"
ports: 8000
debug:
keep_alive: 5
read_timeout: 5
write_timeout: 5
log_level: "normal"
limits:
forms: 32768
jwt:
key: "secret"
refresh_token_size: 64
# Just 5 seconds for debugging
refresh_token_expire: 60
databases:
postgres_rb:
url: "postgres://rb:rb@localhost:5433/rb"
release:
keep_alive: 5
read_timeout: 5
write_timeout: 5
log_level: "normal"
limits:
forms: 32768
admin_user: "admin"
admin_pass: "password"
jwt:
key: "secret"
refresh_token_size: 64
# Just 5 seconds for debugging
refresh_token_expire: 60
databases:
postgres_rb:
url: "postgres://rb:rb@db:5432/rb"

View File

@ -26,7 +26,7 @@ pub struct RbDbConn(diesel::PgConnection);
#[catch(default)]
fn default_catcher(status: Status, _: &Request) -> Value
{
json!({"status": status.code, "message": ""})
json!({"status": status.code, "message": "Not found."})
}
embed_migrations!();
@ -46,8 +46,6 @@ async fn run_db_migrations(rocket: Rocket<Build>) -> Result<Rocket<Build>, Rocke
#[derive(Debug, Deserialize, Serialize)]
pub struct RbConfig
{
admin_user: String,
admin_pass: String,
jwt: JwtConf,
}
@ -58,17 +56,20 @@ fn rocket() -> _
.merge(Yaml::file("Rb.yaml").nested())
.merge(Env::prefixed("RB_").global());
// This mut is necessary when the "docs" or "web" feature is enabled, as these further modify
// the instance variable
rocket::custom(figment)
let rocket = rocket::custom(figment)
.attach(RbDbConn::fairing())
.attach(AdHoc::try_on_ignite(
"Run database migrations",
run_db_migrations,
))
// .attach(AdHoc::try_on_ignite("Create admin user", create_admin_user))
.attach(AdHoc::config::<JwtConf>())
// .attach(AdHoc::config::<JwtConf>())
.register("/", catchers![default_catcher])
.mount("/sections", routes![sections::create_section])
.mount("/posts", routes![posts::get, posts::create])
.mount("/posts", routes![posts::get, posts::create]);
let new_figment = rocket.figment();
let jwt_conf: JwtConf = new_figment.extract_inner("jwt").expect("jwt config");
rocket.manage(jwt_conf)
}

View File

@ -1,9 +1,6 @@
//! This module handles management of site sections (aka blogs).
use rb::{
errors::{RbOption, RbResult},
guards::Admin,
};
use rb::{errors::RbResult, guards::Admin};
use rb_blog::db;
use rocket::serde::json::Json;