Add option to disable frontend

This commit is contained in:
Lennart
2025-01-19 12:28:17 +01:00
parent 6485b89c73
commit cde1b8f51f
5 changed files with 27 additions and 15 deletions

View File

@@ -1,9 +1,15 @@
use serde::{Deserialize, Serialize};
fn default_enabled() -> bool {
true
}
#[derive(Deserialize, Serialize, Debug, Clone)]
#[serde(deny_unknown_fields)]
pub struct FrontendConfig {
#[serde(serialize_with = "hex::serde::serialize")]
#[serde(deserialize_with = "hex::serde::deserialize")]
pub secret_key: [u8; 64],
#[serde(default = "default_enabled")]
pub enabled: bool,
}

View File

@@ -23,7 +23,7 @@ pub fn make_app<AS: AddressbookStore, CS: CalendarStore, S: SubscriptionStore>(
Error = actix_web::Error,
>,
> {
App::new()
let mut app = App::new()
// .wrap(Logger::new("[%s] %r"))
.wrap(TracingLogger::default())
.wrap(NormalizePath::trim())
@@ -50,7 +50,10 @@ pub fn make_app<AS: AddressbookStore, CS: CalendarStore, S: SubscriptionStore>(
.configure(|cfg| {
rustical_carddav::configure_well_known(cfg, "/carddav".to_string())
}),
)
);
if frontend_config.enabled {
app = app
.service(web::scope("/frontend").configure(|cfg| {
configure_frontend(
cfg,
@@ -60,5 +63,7 @@ pub fn make_app<AS: AddressbookStore, CS: CalendarStore, S: SubscriptionStore>(
frontend_config,
)
}))
.service(web::redirect("/", "/frontend").see_other())
.service(web::redirect("/", "/frontend").see_other());
}
app
}

View File

@@ -46,6 +46,7 @@ pub fn cmd_gen_config(_args: GenConfigArgs) -> anyhow::Result<()> {
tracing: TracingConfig::default(),
frontend: FrontendConfig {
secret_key: generate_frontend_secret(),
enabled: true,
},
dav_push: DavPushConfig::default(),
};

View File

@@ -47,7 +47,7 @@ pub struct TracingConfig {
#[derive(Debug, Deserialize, Serialize)]
#[serde(deny_unknown_fields, default)]
pub struct DavPushConfig {
pub enable: bool,
pub enabled: bool,
#[serde(default)]
// Allowed Push servers, accepts any by default
// Specify as URL origins
@@ -57,7 +57,7 @@ pub struct DavPushConfig {
impl Default for DavPushConfig {
fn default() -> Self {
Self {
enable: true,
enabled: true,
allowed_push_servers: None,
}
}

View File

@@ -82,7 +82,7 @@ async fn main() -> Result<()> {
let (addr_store, cal_store, subscription_store, update_recv) =
get_data_stores(!args.no_migrations, &config.data_store).await?;
if config.dav_push.enable {
if config.dav_push.enabled {
tokio::spawn(push_notifier(
config.dav_push.allowed_push_servers,
update_recv,