diff --git a/crates/ton-localnet/Cargo.toml b/crates/ton-localnet/Cargo.toml index d08c963822..e2570d5e84 100644 --- a/crates/ton-localnet/Cargo.toml +++ b/crates/ton-localnet/Cargo.toml @@ -31,9 +31,13 @@ tracing = { workspace = true } rusqlite = { workspace = true } ton-indexer = { workspace = true } url = { workspace = true } -include_dir = { workspace = true } +include_dir = { workspace = true, optional = true } reqwest = { workspace = true } +[features] +default = ["ui"] +ui = ["dep:include_dir"] + [lints] workspace = true diff --git a/crates/ton-localnet/src/server/router.rs b/crates/ton-localnet/src/server/router.rs index f580c4216f..1fe5962faa 100644 --- a/crates/ton-localnet/src/server/router.rs +++ b/crates/ton-localnet/src/server/router.rs @@ -20,21 +20,21 @@ use axum::{ response::{IntoResponse, Response}, routing::{get, post}, }; -#[cfg(not(debug_assertions))] +#[cfg(all(not(debug_assertions), feature = "ui"))] use include_dir::{Dir, include_dir}; use serde_json::json; -#[cfg(debug_assertions)] +#[cfg(all(debug_assertions, feature = "ui"))] use std::path::PathBuf; use std::sync::Arc; use tower_governor::governor::GovernorConfigBuilder; use tower_governor::key_extractor::GlobalKeyExtractor; use tower_governor::{GovernorError, GovernorLayer}; use tower_http::cors::{AllowOrigin, Any, CorsLayer}; -#[cfg(debug_assertions)] +#[cfg(all(debug_assertions, feature = "ui"))] use tower_http::services::{ServeDir, ServeFile}; use tower_http::trace::TraceLayer; -#[cfg(not(debug_assertions))] +#[cfg(all(not(debug_assertions), feature = "ui"))] static UI_DIR: Dir<'static> = include_dir!("$CARGO_MANIFEST_DIR/../acton-localnet-ui/dist"); pub fn create_router(state: ServerState, rate_limit_rps: Option) -> Router { @@ -137,7 +137,7 @@ pub fn create_router(state: ServerState, rate_limit_rps: Option) -> Router .layer(TraceLayer::new_for_http()) .with_state(state); - #[cfg(debug_assertions)] + #[cfg(all(debug_assertions, feature = "ui"))] let app = { let dist_path = PathBuf::from(concat!( env!("CARGO_MANIFEST_DIR"), @@ -148,7 +148,7 @@ pub fn create_router(state: ServerState, rate_limit_rps: Option) -> Router ) }; - #[cfg(not(debug_assertions))] + #[cfg(all(not(debug_assertions), feature = "ui"))] let app = app.fallback(handle_embedded_ui); app @@ -230,7 +230,7 @@ fn governor_error_response(error: GovernorError, max_requests_per_second: u32) - } } -#[cfg(not(debug_assertions))] +#[cfg(all(not(debug_assertions), feature = "ui"))] async fn handle_embedded_ui(uri: axum::http::Uri) -> impl IntoResponse { let path = uri.path().trim_start_matches('/'); let path = if path.is_empty() { "index.html" } else { path };