35 lines
910 B
Rust
35 lines
910 B
Rust
|
mod db;
|
||
|
mod schema;
|
||
|
mod dto;
|
||
|
mod routes;
|
||
|
mod config;
|
||
|
|
||
|
#[tokio::main]
|
||
|
async fn main() {
|
||
|
console_subscriber::init();
|
||
|
|
||
|
pretty_env_logger::formatted_builder().filter_level(log::LevelFilter::Info).init();
|
||
|
|
||
|
let _ = config::CONFIG;
|
||
|
|
||
|
let pool: db::DBPool = db::build_pool();
|
||
|
|
||
|
db::run_migrations(&mut pool.get().unwrap());
|
||
|
|
||
|
if !std::path::Path::new("files").exists() {
|
||
|
std::fs::create_dir("files").expect("Failed to create files directory");
|
||
|
}
|
||
|
|
||
|
let (shutdown_tx, shutdown_rx) = tokio::sync::oneshot::channel();
|
||
|
|
||
|
let (_addr, server) = warp::serve(routes::build_routes(pool.clone())).bind_with_graceful_shutdown(([0, 0, 0, 0], 2345), async {
|
||
|
shutdown_rx.await.ok();
|
||
|
});
|
||
|
|
||
|
tokio::task::spawn(server);
|
||
|
|
||
|
tokio::signal::ctrl_c().await.expect("Failed to wait for ctrl-c");
|
||
|
println!("Quitting");
|
||
|
shutdown_tx.send(()).expect("Failed to shutdown server");
|
||
|
}
|