2022-04-16 22:09:23 +00:00
|
|
|
mod init;
|
|
|
|
|
2022-04-18 12:13:15 +00:00
|
|
|
use homedisk_utils::{config::Config, database::Database};
|
2022-04-16 18:19:38 +00:00
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
2022-04-16 22:09:23 +00:00
|
|
|
init::init();
|
2022-04-16 18:19:38 +00:00
|
|
|
|
2022-04-18 12:13:15 +00:00
|
|
|
let config = Config::parse().expect("parse configuration file");
|
2022-04-16 19:22:01 +00:00
|
|
|
|
2022-04-19 11:05:47 +00:00
|
|
|
let db = Database::open("homedisk.db")
|
|
|
|
.await
|
|
|
|
.expect("open SQLite database");
|
2022-04-17 22:07:37 +00:00
|
|
|
|
2022-04-18 12:13:15 +00:00
|
|
|
// change the type from Vec<String> to Vec<HeaderValue> so that the http server can correctly detect CORS hosts
|
|
|
|
let origins = config
|
|
|
|
.http
|
|
|
|
.cors
|
|
|
|
.iter()
|
|
|
|
.map(|e| e.parse().expect("parse CORS host"))
|
|
|
|
.collect();
|
2022-04-17 22:07:37 +00:00
|
|
|
|
2022-04-18 12:13:15 +00:00
|
|
|
homedisk_server::serve(config.http.host, origins, db)
|
|
|
|
.await
|
|
|
|
.expect("start http server");
|
2022-04-16 18:19:38 +00:00
|
|
|
}
|