Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion crates/ton-localnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 7 additions & 7 deletions crates/ton-localnet/src/server/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32>) -> Router {
Expand Down Expand Up @@ -137,7 +137,7 @@ pub fn create_router(state: ServerState, rate_limit_rps: Option<u32>) -> 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"),
Expand All @@ -148,7 +148,7 @@ pub fn create_router(state: ServerState, rate_limit_rps: Option<u32>) -> Router
)
};

#[cfg(not(debug_assertions))]
#[cfg(all(not(debug_assertions), feature = "ui"))]
let app = app.fallback(handle_embedded_ui);

app
Expand Down Expand Up @@ -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 };
Expand Down