diff --git a/src/config.rs b/src/config.rs index 63a699d..c57bf7c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -17,8 +17,19 @@ pub struct Config { #[serde(default)] pub template: ConfigTemplate, + + #[serde(default)] + pub routing: ConfigRouting, } +#[serde_inline_default] +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, serde_default::DefaultFromSerde)] +pub struct ConfigRouting { + #[serde_inline_default("/".into())] + pub redirect: String, +} + + #[serde_inline_default] #[derive(Debug, Clone, serde::Serialize, serde::Deserialize, serde_default::DefaultFromSerde)] pub struct ConfigOverrides { diff --git a/src/main.rs b/src/main.rs index 5910b87..21060d3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -115,7 +115,7 @@ async fn main() { if_using_sqlite_driver_and_file_is_missing_create_it_beforehand(&args.db); let storage = StorageProvider::connect(&args.db, config.overrides).await.unwrap(); - let mut state = Context::new(storage, #[cfg(feature = "web")] config.template); + let mut state = Context::new(storage, config.routing, #[cfg(feature = "web")] config.template); for notifier in config.notifiers.providers { match notifier { diff --git a/src/routes.rs b/src/routes.rs index 198940c..b602078 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use axum::{Json, Form, Router, routing::{put, post, get}, extract::{State, Query}, response::{Redirect, Html}}; use axum_extra::response::{Css, JavaScript}; -use crate::{notifications::NotificationProcessor, model::{Page, PageOptions, PageInsertion, PageView}, storage::StorageProvider, web::IndexTemplate}; +use crate::{notifications::NotificationProcessor, model::{Page, PageOptions, PageInsertion, PageView}, storage::StorageProvider, web::IndexTemplate, config::ConfigRouting}; pub fn create_router_with_app_routes(state: Context) -> Router { let mut router = Router::new() @@ -31,6 +31,7 @@ pub fn create_router_with_app_routes(state: Context) -> Router { pub struct Context { providers: Vec>>, storage: StorageProvider, + routing: ConfigRouting, #[cfg(feature = "web")] template: crate::config::ConfigTemplate, @@ -39,11 +40,12 @@ pub struct Context { impl Context { pub fn new( storage: StorageProvider, + routing: ConfigRouting, #[cfg(feature = "web")] template: crate::config::ConfigTemplate, ) -> Self { Context { providers: Vec::new(), - storage, + storage, routing, #[cfg(feature = "web")] template, } } @@ -61,7 +63,7 @@ async fn send_suggestion(payload: PageInsertion, state: Arc) -> Result< for p in state.providers.iter() { p.process(&page).await; } - Ok(Redirect::to("/")) + Ok(Redirect::to(&state.routing.redirect)) }, } }