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.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586#![deny(clippy::unwrap_used, clippy::expect_used)]
use axum::{Router, routing::get};use color_eyre::eyre;use http::{ HeaderName, 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::events::EventService;
pub mod auth;mod jobs;mod routes;
#[derive(Clone)]struct AppState { db_connection: OrmConnection, event_service: EventService, allow_test_user: bool, 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, allow_test_user: bool, 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(), allow_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)) .route("/health", get(health_check)) .layer( ServiceBuilder::new() .layer(TraceLayer::new_for_http()) .layer( CorsLayer::new() .allow_headers([ AUTHORIZATION, CONTENT_TYPE, ACCEPT, HeaderName::from_static("x-org-id"), ]) .allow_origin(Any) .allow_methods(Any), ), );
Ok(app)}
async fn health_check() -> &'static str { "ok"}