diff --git a/crates/weaver-app/src/lib.rs b/crates/weaver-app/src/lib.rs index 593082f..72a58ee 100644 --- a/crates/weaver-app/src/lib.rs +++ b/crates/weaver-app/src/lib.rs @@ -53,6 +53,11 @@ use crate::{ subdomain_app::{extract_subdomain, lookup_subdomain_context}, }; +/// Reserved subdomains that should not be used for notebooks. +const RESERVED_SUBDOMAINS: &[&str] = &[ + "www", "api", "admin", "app", "auth", "cdn", "alpha", "beta", "staging", "index", +]; + #[derive(Debug, Clone, Routable, PartialEq)] #[rustfmt::skip] pub enum Route { @@ -179,6 +184,13 @@ pub fn App() -> Element { ); return None; }; + + // Check if subdomain is reserved + if RESERVED_SUBDOMAINS.contains(&subdomain.as_str()) { + tracing::info!(subdomain, "Reserved subdomain, skipping notebook lookup"); + return None; + } + // Look up notebook by global path let result = lookup_subdomain_context(&fetcher, &subdomain).await; if result.is_none() { diff --git a/crates/weaver-app/src/main.rs b/crates/weaver-app/src/main.rs index 4dfaf4d..2148d8f 100644 --- a/crates/weaver-app/src/main.rs +++ b/crates/weaver-app/src/main.rs @@ -118,57 +118,3 @@ fn main() { #[cfg(not(feature = "server"))] dioxus::launch(App); } - -/// Extract subdomain from host if it matches base domain pattern. -#[cfg(feature = "server")] -fn extract_subdomain<'a>(host: &'a str, base: &str) -> Option<&'a str> { - let suffix = format!(".{}", base); - if host.ends_with(&suffix) && host.len() > suffix.len() { - Some(&host[..host.len() - suffix.len()]) - } else { - None - } -} - -/// Look up notebook by global path. -/// -/// Returns SubdomainContext if a notebook with publishGlobal=true exists for this path. -#[cfg(feature = "server")] -async fn lookup_global_notebook( - fetcher: &Arc, - path: &str, -) -> Option { - use jacquard::IntoStatic; - use jacquard::smol_str::SmolStr; - use jacquard::smol_str::ToSmolStr; - use jacquard::types::string::Did; - use jacquard::xrpc::XrpcClient; - use weaver_api::sh_weaver::notebook::resolve_global_notebook::ResolveGlobalNotebook; - - let request = ResolveGlobalNotebook::new().path(path).build(); - - match fetcher.send(request).await { - Ok(response) => { - let output = response.into_output().ok()?; - let notebook = output.notebook; - - let owner = notebook.uri.authority().clone().into_static(); - let rkey = notebook.uri.rkey()?.0.to_smolstr(); - let notebook_path = notebook - .path - .map(|p| SmolStr::new(p.as_ref())) - .unwrap_or_else(|| SmolStr::new(path)); - - Some(SubdomainContext { - owner, - notebook_path, - notebook_rkey: rkey, - notebook_title: notebook.title.clone().unwrap_or_default().to_smolstr(), - }) - } - Err(e) => { - tracing::debug!(path = path, error = %e, "Global notebook lookup failed"); - None - } - } -}