-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rs
43 lines (37 loc) · 1.31 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
extern crate rocket;
use figment::providers::Format;
use rocket::fairing::AdHoc;
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct Config {
pub db: String,
}
impl Default for Config {
fn default() -> Self {
Self { db: "".to_owned() }
}
}
#[rocket::launch]
async fn get_rocket() -> rocket::Rocket<rocket::Build> {
env_logger::init();
let figment = rocket::Config::figment()
.merge(figment::providers::Serialized::defaults(Config::default()))
.merge(figment::providers::Toml::file("ircj-serve.toml"))
.merge(figment::providers::Env::prefixed("IRCJ_"));
rocket::custom(figment)
.attach(AdHoc::config::<Config>())
.attach(AdHoc::on_ignite(
"Connect to database and migrate",
|rocket| async move {
let db = rocket.state::<Config>().unwrap().db.clone(); // attached above.
rocket.manage(
ircjournal::db::create_db(&db)
.await
.expect("connecting and migrating the DB"),
)
},
))
.attach(ircj_serve::watch::fairing())
.register("/", ircj_serve::route::catchers())
.mount("/static", ircj_serve::route::StaticFiles {})
.mount("/", ircj_serve::route::routes())
}