From 8507a327290b6709a4bdd84adffeaa865dcfe4e5 Mon Sep 17 00:00:00 2001 From: Zahin Mohammad Date: Wed, 4 Sep 2024 11:04:35 -0400 Subject: [PATCH 1/5] feat(admin): host and port set via env vars This allows users to use ipv4 or ipv6 --- admin_frontend/src/config.rs | 11 ++++++++--- admin_frontend/src/main.rs | 5 +++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/admin_frontend/src/config.rs b/admin_frontend/src/config.rs index 057dc326..f9326e82 100644 --- a/admin_frontend/src/config.rs +++ b/admin_frontend/src/config.rs @@ -2,21 +2,26 @@ use tracing::warn; #[derive(Debug, Clone)] pub struct Config { + pub host: String, + pub port: u16, pub redis_url: String, pub gotrue_url: String, pub appflowy_cloud_url: String, } impl Config { - pub fn from_env() -> Self { - Config { + pub fn from_env() -> Result { + let cfg = Config { + host: get_or_default("ADMIN_FRONTEND_HOST", "0.0.0.0"), + port: get_or_default("ADMIN_FRONTEND_PORT", "3000").parse()?, redis_url: get_or_default("ADMIN_FRONTEND_REDIS_URL", "redis://localhost:6379"), gotrue_url: get_or_default("ADMIN_FRONTEND_GOTRUE_URL", "http://localhost:9999"), appflowy_cloud_url: get_or_default( "ADMIN_FRONTEND_APPFLOWY_CLOUD_URL", "http://localhost:8000", ), - } + }; + Ok(cfg) } } diff --git a/admin_frontend/src/main.rs b/admin_frontend/src/main.rs index 229ab9b3..cdf845ba 100644 --- a/admin_frontend/src/main.rs +++ b/admin_frontend/src/main.rs @@ -27,7 +27,7 @@ async fn main() { .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) .init(); - let config = Config::from_env(); + let config = Config::from_env().unwrap(); info!("config loaded: {:?}", &config); let gotrue_client = gotrue::api::Client::new(reqwest::Client::new(), &config.gotrue_url); @@ -65,7 +65,8 @@ async fn main() { .nest_service("/web-api", web_api_router) .nest_service("/assets", ServeDir::new("assets")); - let listener = TcpListener::bind("0.0.0.0:3000") + let address = format!("{}:{}", config.host, config.port); + let listener = TcpListener::bind(address) .await .expect("failed to bind to port"); info!("listening on: {:?}", listener); From fa5f548c9539f1e990a9264576fb72ce90a4aa20 Mon Sep 17 00:00:00 2001 From: Zahin Mohammad Date: Wed, 4 Sep 2024 11:04:49 -0400 Subject: [PATCH 2/5] feat(admin): expose container port via env var --- admin_frontend/Dockerfile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/admin_frontend/Dockerfile b/admin_frontend/Dockerfile index 1203ca72..c2c28daa 100644 --- a/admin_frontend/Dockerfile +++ b/admin_frontend/Dockerfile @@ -40,4 +40,10 @@ COPY --from=builder /app/target/release/admin_frontend /usr/local/bin/admin_fron COPY --from=builder /app/admin_frontend/assets /app/assets ENV RUST_BACKTRACE 1 ENV RUST_LOG info + +ARG ADMIN_FRONTEND_PORT +ARG PORT +ENV PORT=${ADMIN_FRONTEND_PORT:-${PORT:-3000}} +EXPOSE $PORT + CMD ["admin_frontend"] From 9fc15827f80057bfb98121d0091143a408472eb9 Mon Sep 17 00:00:00 2001 From: Zahin Mohammad Date: Wed, 4 Sep 2024 11:05:06 -0400 Subject: [PATCH 3/5] feat(af-cloud): expose container port via env var --- Dockerfile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Dockerfile b/Dockerfile index a38e1580..de8b7272 100644 --- a/Dockerfile +++ b/Dockerfile @@ -40,4 +40,10 @@ RUN apt-get update -y \ COPY --from=builder /app/target/release/appflowy_cloud /usr/local/bin/appflowy_cloud ENV APP_ENVIRONMENT production ENV RUST_BACKTRACE 1 + +ARG APPFLOWY_APPLICATION_PORT +ARG PORT +ENV PORT=${APPFLOWY_APPLICATION_PORT:-${PORT:-8000}} +EXPOSE $PORT + CMD ["appflowy_cloud"] From df14ecbfbde1eabf03cb52be564f71f7bc32a806 Mon Sep 17 00:00:00 2001 From: khorshuheng Date: Fri, 6 Sep 2024 11:02:53 +0800 Subject: [PATCH 4/5] fix: hide space without any published documents, allow private published collab --- src/biz/collab/publish_outline.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/biz/collab/publish_outline.rs b/src/biz/collab/publish_outline.rs index eb9ba5bf..10b5b75f 100644 --- a/src/biz/collab/publish_outline.rs +++ b/src/biz/collab/publish_outline.rs @@ -4,16 +4,13 @@ use app_error::AppError; use collab_folder::Folder; use shared_entity::dto::workspace_dto::PublishedView; -use super::folder_view::{to_dto_view_icon, to_view_layout, view_is_space}; +use super::folder_view::{to_dto_view_icon, to_view_layout}; pub fn collab_folder_to_published_outline( folder: &Folder, publish_view_ids: &HashSet, ) -> Result { let mut unviewable = HashSet::new(); - for private_section in folder.get_all_private_sections() { - unviewable.insert(private_section.id); - } for trash_view in folder.get_all_trash_sections() { unviewable.insert(trash_view.id); } @@ -117,7 +114,7 @@ fn to_publish_view( }) .collect(); let is_published = publish_view_ids.contains(view_id); - if view_is_space(&view) || is_published || !pruned_view.is_empty() { + if is_published || !pruned_view.is_empty() { Some(PublishedView { view_id: view.id.clone(), name: view.name.clone(), From 6e4c9840be1882e726e69a1e4cbaeee5633cc2e6 Mon Sep 17 00:00:00 2001 From: khorshuheng Date: Mon, 9 Sep 2024 11:44:26 +0800 Subject: [PATCH 5/5] chore: fix formating and add descriptive error message for parse failures --- admin_frontend/src/config.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/admin_frontend/src/config.rs b/admin_frontend/src/config.rs index f9326e82..a6aa2a80 100644 --- a/admin_frontend/src/config.rs +++ b/admin_frontend/src/config.rs @@ -10,10 +10,12 @@ pub struct Config { } impl Config { - pub fn from_env() -> Result { + pub fn from_env() -> Result { let cfg = Config { host: get_or_default("ADMIN_FRONTEND_HOST", "0.0.0.0"), - port: get_or_default("ADMIN_FRONTEND_PORT", "3000").parse()?, + port: get_or_default("ADMIN_FRONTEND_PORT", "3000") + .parse() + .map_err(|e| anyhow::anyhow!("failed to parse ADMIN_FRONTEND_PORT as u16, err: {}", e))?, redis_url: get_or_default("ADMIN_FRONTEND_REDIS_URL", "redis://localhost:6379"), gotrue_url: get_or_default("ADMIN_FRONTEND_GOTRUE_URL", "http://localhost:9999"), appflowy_cloud_url: get_or_default(