48 lines
1.1 KiB
Rust
48 lines
1.1 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::InitialisationError),
|
|
|
|
#[error("{0}")]
|
|
IOError(#[from] std::io::Error),
|
|
}
|
|
|
|
fn main() {
|
|
let runtime = tokio::runtime::Runtime::new().unwrap();
|
|
std::process::exit(match runtime.block_on(locality_main()) {
|
|
Ok(()) => 0,
|
|
Err(err) => {
|
|
eprintln!("ERROR: {}", err);
|
|
1
|
|
}
|
|
})
|
|
}
|
|
|
|
async fn locality_main() -> Result<(), Error> {
|
|
let config = get_config()?;
|
|
|
|
let db_pool = Database::new(&config.database_url)?;
|
|
|
|
db_pool.migrate_to_current_version().await.unwrap();
|
|
|
|
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(())
|
|
}
|