From 5e876a54a2d156e93983507322da561a46552f38 Mon Sep 17 00:00:00 2001 From: frectonz Date: Thu, 27 Jun 2024 23:05:24 +0300 Subject: [PATCH] feat: use `--base-path` instead of `--base-url` --- Cargo.lock | 1 - Cargo.toml | 1 - src/main.rs | 9 ++++----- ui/src/api.ts | 10 +++++----- ui/src/main.tsx | 8 ++++---- 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8485144..5dc4c65 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3023,7 +3023,6 @@ dependencies = [ "tokio-rusqlite", "tracing", "tracing-subscriber", - "url", "warp", ] diff --git a/Cargo.toml b/Cargo.toml index 594c5a5..7c750db 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,6 @@ tokio-postgres = "0.7.10" mysql_async = { version = "0.34.1", default-features = false, features = ["rustls-tls", "default-rustls"] } duckdb = { git = "https://github.com/frectonz/duckdb-rs.git", features = ["bundled"] } humantime = "2.1.0" -url = "2.5.2" [profile.release] strip = true diff --git a/src/main.rs b/src/main.rs index 45e005f..4d6321a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,5 @@ use async_trait::async_trait; use clap::{Parser, Subcommand}; -use url::Url; use warp::Filter; const ROWS_PER_PAGE: i32 = 50; @@ -20,9 +19,9 @@ struct Args { #[clap(short, long, default_value = "5secs")] timeout: humantime::Duration, - /// Base URL used by a reverse proxy. [e.g http://localhost:8080/sql-studio] + /// Base path to be provided to the UI. [e.g /sql-studio] #[clap(short, long)] - base_url: Option, + base_path: Option, } #[derive(Debug, Subcommand)] @@ -95,8 +94,8 @@ async fn main() -> color_eyre::Result<()> { }; let mut index_html = statics::get_index_html()?; - if let Some(ref base_url) = args.base_url { - let base = format!(r#""#); + if let Some(ref base_path) = args.base_path { + let base = format!(r#""#); index_html = index_html.replace(r#""#, &base); } diff --git a/ui/src/api.ts b/ui/src/api.ts index 34be02c..a95d278 100644 --- a/ui/src/api.ts +++ b/ui/src/api.ts @@ -1,12 +1,12 @@ import { z } from "zod"; import { createZodFetcher } from "zod-fetch"; -let baseMeta = document.querySelector( - `meta[name="BASE_URL"]`, -) as HTMLMetaElement; +let basePath = document.querySelector( + `meta[name="BASE_PATH"]`, +); const BASE_URL = import.meta.env.PROD - ? baseMeta - ? `${baseMeta.content}/api` + ? basePath + ? `${basePath.content}/api` : "/api" : "http://localhost:3030/api"; diff --git a/ui/src/main.tsx b/ui/src/main.tsx index 1d93672..51c50ea 100644 --- a/ui/src/main.tsx +++ b/ui/src/main.tsx @@ -9,10 +9,10 @@ import ReactDOM from "react-dom/client"; import { ThemeProvider } from "./provider/theme.provider"; import { routeTree } from "./routeTree.gen"; -let baseUrl = document.querySelector( - `meta[name="BASE_URL"]`, -) as HTMLMetaElement; -let basepath = baseUrl ? new URL(baseUrl.content).pathname : "/"; +let basePath = document.querySelector( + `meta[name="BASE_PATH"]`, +); +let basepath = basePath?.content ?? "/"; // Create a new router instance const router = createRouter({ routeTree, basepath });