2022-04-16 22:09:23 +00:00
|
|
|
mod init;
|
|
|
|
|
2022-04-23 18:44:02 +00:00
|
|
|
use homedisk_database::Database;
|
2022-06-07 20:36:26 +00:00
|
|
|
use homedisk_server::run_http_server;
|
2022-04-19 19:10:36 +00:00
|
|
|
use homedisk_types::config::types::Config;
|
2022-04-16 18:19:38 +00:00
|
|
|
|
|
|
|
#[tokio::main]
|
2022-06-07 20:36:26 +00:00
|
|
|
async fn main() -> anyhow::Result<()> {
|
|
|
|
init::init()?;
|
2022-04-16 18:19:38 +00:00
|
|
|
|
2022-06-07 20:36:26 +00:00
|
|
|
// parse config
|
|
|
|
let config = Config::parse()?;
|
2022-04-16 19:22:01 +00:00
|
|
|
|
2022-06-07 20:36:26 +00:00
|
|
|
// open database connection
|
|
|
|
let db = Database::open("homedisk.db").await?;
|
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()
|
2022-06-07 20:36:26 +00:00
|
|
|
.map(|e| e.parse().expect("parse CORS hosts"))
|
2022-04-18 12:13:15 +00:00
|
|
|
.collect();
|
2022-04-17 22:07:37 +00:00
|
|
|
|
2022-04-19 13:25:56 +00:00
|
|
|
let host = format!(
|
|
|
|
"{host}:{port}",
|
|
|
|
host = config.http.host,
|
|
|
|
port = config.http.port
|
|
|
|
);
|
|
|
|
|
2022-06-07 20:36:26 +00:00
|
|
|
// start http server
|
|
|
|
run_http_server(host, origins, db, config).await?;
|
|
|
|
|
|
|
|
Ok(())
|
2022-04-16 18:19:38 +00:00
|
|
|
}
|