Something went wrong. Try again.
A simple to-do app focused on tasks that can be completed within a specific time span.
Something went wrong. Try again.
Rust
at rust-backend
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273#![deny(clippy::unwrap_used, clippy::expect_used)]
use axum::Router;use color_eyre::eyre;use http::header::{ACCEPT, AUTHORIZATION, CONTENT_TYPE};use orm::{OrmConnection, init_db};use tower::ServiceBuilder;use tower_http::{ cors::{Any, CorsLayer}, trace::TraceLayer,};
use crate::{auth::JwksCache, jobs::web_push_notifications::run_web_push_job};use services::{User, events::EventService};
pub mod auth;mod jobs;mod routes;
#[derive(Clone)]struct AppState { db_connection: OrmConnection, event_service: EventService, test_user: Option<User>, constants: Constants, jwks_cache: JwksCache,}
#[derive(Clone)]pub struct Constants { web_push_key: Option<String>, auth_api_base: String, self_api_base: String,}
pub async fn app( db_url: &str, test_user: Option<User>, web_push_key: Option<String>, auth_api_base: String, self_api_base: String,) -> eyre::Result<Router> { let state = AppState { db_connection: init_db(db_url).await?, event_service: EventService::default(), test_user, constants: Constants { web_push_key, auth_api_base, self_api_base, }, jwks_cache: JwksCache::default(), };
run_web_push_job(state.clone()).await;
let app = Router::new() .with_state(state.clone()) .nest("/api", routes::routes(state.clone())) .layer( ServiceBuilder::new() .layer(TraceLayer::new_for_http()) .layer( CorsLayer::new() .allow_headers([AUTHORIZATION, CONTENT_TYPE, ACCEPT]) .allow_origin(Any) .allow_methods(Any), ), );
Ok(app)}