little-hesinde/cops-web/src/main.rs

51 lines
1.2 KiB
Rust
Raw Normal View History

2024-05-02 16:10:29 +00:00
use std::sync::Arc;
use app_state::AppState;
use calibre_db::calibre::Calibre;
use clap::Parser;
use cli::Cli;
use config::Config;
use poem::{
endpoint::EmbeddedFilesEndpoint, get, listener::TcpListener, EndpointExt, Route, Server,
};
use rust_embed::RustEmbed;
mod app_state;
mod basic_auth;
mod cli;
mod config;
mod handlers {
pub mod cover;
pub mod recents;
}
mod templates;
#[derive(RustEmbed)]
#[folder = "static"]
pub struct Files;
#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
if std::env::var_os("RUST_LOG").is_none() {
std::env::set_var("RUST_LOG", "debug");
}
tracing_subscriber::fmt::init();
let args = Cli::parse();
let config = Config::load(&args).expect("failed to load configuration");
let calibre = Calibre::load(&config.metadata_path).expect("failed to load calibre database");
let app_state = Arc::new(AppState { calibre, config });
let app = Route::new()
.at("/", get(handlers::recents::handler))
.at("/cover/:id", get(handlers::cover::handler))
.nest("/static", EmbeddedFilesEndpoint::<Files>::new())
.data(app_state);
Server::new(TcpListener::bind("[::]:3000"))
.name("cops-web")
.run(app)
.await
}