46 lines
1.0 KiB
Rust
46 lines
1.0 KiB
Rust
use {thiserror::Error, tower_http::services::ServeDir};
|
|
|
|
mod app;
|
|
mod config;
|
|
mod db;
|
|
|
|
use config::get_config;
|
|
use db::Database;
|
|
|
|
#[derive(Error, Debug)]
|
|
pub enum Error {
|
|
#[error("Loading configuration: \"{0}\"")]
|
|
MissingConfigError(#[from] config::Error),
|
|
|
|
#[error("Database error: {0}")]
|
|
DatabaseError(#[from] db::Error),
|
|
|
|
#[error("{0}")]
|
|
IOError(#[from] std::io::Error),
|
|
}
|
|
|
|
fn main() {
|
|
let runtime = tokio::runtime::Runtime::new().unwrap();
|
|
std::process::exit(match runtime.block_on(localhub_main()) {
|
|
Ok(()) => 0,
|
|
Err(err) => {
|
|
eprintln!("ERROR: {}", err);
|
|
1
|
|
}
|
|
})
|
|
}
|
|
|
|
async fn localhub_main() -> Result<(), Error> {
|
|
let config = get_config()?;
|
|
|
|
let db_pool = Database::create_pool(&config.database_url, 2)?;
|
|
|
|
let app = app::routes()
|
|
.with_state(db_pool)
|
|
.nest_service("/static", ServeDir::new(&config.static_file_path));
|
|
|
|
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await?;
|
|
axum::serve(listener, app).await?;
|
|
Ok(())
|
|
}
|