mirror of
https://git.alemi.dev/guestbook.rs.git
synced 2024-12-18 18:54:51 +01:00
feat: allow configuring redirect url
This commit is contained in:
parent
7fe7463b54
commit
6daf50a81e
3 changed files with 17 additions and 4 deletions
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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<Box<dyn NotificationProcessor<Page>>>,
|
||||
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<Context>) -> Result<
|
|||
for p in state.providers.iter() {
|
||||
p.process(&page).await;
|
||||
}
|
||||
Ok(Redirect::to("/"))
|
||||
Ok(Redirect::to(&state.routing.redirect))
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue