diff --git a/crates/app/src/cmd_serve.rs b/crates/app/src/cmd_serve.rs index 127836936..c6a68f9ee 100755 --- a/crates/app/src/cmd_serve.rs +++ b/crates/app/src/cmd_serve.rs @@ -56,6 +56,8 @@ pub fn run(args: &ServeArgs, build: BuildInfo, extensions: Extensions) -> anyhow // the backend connects or the daemon forks, puts the message on stderr. extenddb_server::validate_extension_prefixes(&extensions.http) .map_err(|e| anyhow::anyhow!("{e}"))?; + extenddb_server::validate_console_slugs(&extensions.console_tabs) + .map_err(|e| anyhow::anyhow!("{e}"))?; // Load config early so bind address is known before fork. A dev-mode // build serves with built-in defaults when no config file exists // (zero-config local/CI use: loopback, in-memory storage, seeded dev diff --git a/crates/app/src/lib.rs b/crates/app/src/lib.rs index 48b3ac389..6eadc64a4 100644 --- a/crates/app/src/lib.rs +++ b/crates/app/src/lib.rs @@ -31,7 +31,8 @@ //! build, //! extenddb_app::Extensions::default() //! .with_router("/_mybackend/status", status_router()) -//! .with_request_observer(my_observer), +//! .with_request_observer(my_observer) +//! .with_console_tab("My backend", "mybackend", page_router()), //! ) //! ``` @@ -67,7 +68,16 @@ pub use extenddb_server::BuildInfo; /// A thin binary's extension points, re-exported from `extenddb-server` so a /// thin `main` needs only the `extenddb-app` dependency to use them. Pass an /// [`Extensions`] to [`run_with`]; [`run`] uses the empty default. -pub use extenddb_server::{Extensions, RequestObserver, RequestRecord}; +pub use extenddb_server::{ + ConsoleIdentity, ConsoleTab, Extensions, RequestObserver, RequestRecord, +}; + +/// The console's HTML helpers (`nav_bar`, `layout_with_version_csrf`, `escape`), +/// so a console tab's page renders the console's layout from its +/// [`ConsoleIdentity`] with the one `extenddb-app` dependency. +pub mod console_html { + pub use extenddb_server::console::html::*; +} /// The `axum` the server is built with, so a thin binary builds its /// [`Extensions::http`] routers against the same `Router` type without naming diff --git a/crates/server/src/console/html.rs b/crates/server/src/console/html.rs index f98f6d4f7..f9e7d3128 100755 --- a/crates/server/src/console/html.rs +++ b/crates/server/src/console/html.rs @@ -182,14 +182,19 @@ const ADMIN_LINKS: &str = concat!( /// Build the navigation bar for an authenticated session. The Accounts, /// Metrics, Settings and Cache links are left out for IAM users, because /// those pages are admin only. An IAM-user session reaches its own user page -/// from the console dashboard. -pub fn nav_bar(identity: &NavIdentity) -> String { +/// from the console dashboard. `tabs` are the extension links shown after +/// the built-in ones, as `(label, href)`. +pub fn nav_bar(identity: &NavIdentity, tabs: &[(String, String)]) -> String { let admin_links = if identity.is_admin { ADMIN_LINKS } else { "" }; + let mut extra = String::new(); + for (label, href) in tabs { + let _ = writeln!(extra, r#"{}"#, escape(href), escape(label)); + } format!( r#"