Added correct config reading
parent
b99d9faa04
commit
6013d0bb6e
|
@ -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"
|
17
src/main.rs
17
src/main.rs
|
@ -26,7 +26,7 @@ pub struct RbDbConn(diesel::PgConnection);
|
||||||
#[catch(default)]
|
#[catch(default)]
|
||||||
fn default_catcher(status: Status, _: &Request) -> Value
|
fn default_catcher(status: Status, _: &Request) -> Value
|
||||||
{
|
{
|
||||||
json!({"status": status.code, "message": ""})
|
json!({"status": status.code, "message": "Not found."})
|
||||||
}
|
}
|
||||||
|
|
||||||
embed_migrations!();
|
embed_migrations!();
|
||||||
|
@ -46,8 +46,6 @@ async fn run_db_migrations(rocket: Rocket<Build>) -> Result<Rocket<Build>, Rocke
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
pub struct RbConfig
|
pub struct RbConfig
|
||||||
{
|
{
|
||||||
admin_user: String,
|
|
||||||
admin_pass: String,
|
|
||||||
jwt: JwtConf,
|
jwt: JwtConf,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,17 +56,20 @@ fn rocket() -> _
|
||||||
.merge(Yaml::file("Rb.yaml").nested())
|
.merge(Yaml::file("Rb.yaml").nested())
|
||||||
.merge(Env::prefixed("RB_").global());
|
.merge(Env::prefixed("RB_").global());
|
||||||
|
|
||||||
// This mut is necessary when the "docs" or "web" feature is enabled, as these further modify
|
let rocket = rocket::custom(figment)
|
||||||
// the instance variable
|
|
||||||
rocket::custom(figment)
|
|
||||||
.attach(RbDbConn::fairing())
|
.attach(RbDbConn::fairing())
|
||||||
.attach(AdHoc::try_on_ignite(
|
.attach(AdHoc::try_on_ignite(
|
||||||
"Run database migrations",
|
"Run database migrations",
|
||||||
run_db_migrations,
|
run_db_migrations,
|
||||||
))
|
))
|
||||||
// .attach(AdHoc::try_on_ignite("Create admin user", create_admin_user))
|
// .attach(AdHoc::try_on_ignite("Create admin user", create_admin_user))
|
||||||
.attach(AdHoc::config::<JwtConf>())
|
// .attach(AdHoc::config::<JwtConf>())
|
||||||
.register("/", catchers![default_catcher])
|
.register("/", catchers![default_catcher])
|
||||||
.mount("/sections", routes![sections::create_section])
|
.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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
//! This module handles management of site sections (aka blogs).
|
//! This module handles management of site sections (aka blogs).
|
||||||
|
|
||||||
use rb::{
|
use rb::{errors::RbResult, guards::Admin};
|
||||||
errors::{RbOption, RbResult},
|
|
||||||
guards::Admin,
|
|
||||||
};
|
|
||||||
use rb_blog::db;
|
use rb_blog::db;
|
||||||
use rocket::serde::json::Json;
|
use rocket::serde::json::Json;
|
||||||
|
|
||||||
|
|
Reference in New Issue