Skip to content

Commit

Permalink
feat: use --base-path instead of --base-url
Browse files Browse the repository at this point in the history
  • Loading branch information
frectonz committed Jun 27, 2024
1 parent 917f970 commit 5e876a5
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<Url>,
base_path: Option<String>,
}

#[derive(Debug, Subcommand)]
Expand Down Expand Up @@ -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#"<meta name="BASE_URL" content="{base_url}" />"#);
if let Some(ref base_path) = args.base_path {
let base = format!(r#"<meta name="BASE_PATH" content="{base_path}" />"#);
index_html = index_html.replace(r#"<!-- __BASE__ -->"#, &base);
}

Expand Down
10 changes: 5 additions & 5 deletions ui/src/api.ts
Original file line number Diff line number Diff line change
@@ -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<HTMLMetaElement>(
`meta[name="BASE_PATH"]`,
);
const BASE_URL = import.meta.env.PROD
? baseMeta
? `${baseMeta.content}/api`
? basePath
? `${basePath.content}/api`
: "/api"
: "http://localhost:3030/api";

Expand Down
8 changes: 4 additions & 4 deletions ui/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLMetaElement>(
`meta[name="BASE_PATH"]`,
);
let basepath = basePath?.content ?? "/";

// Create a new router instance
const router = createRouter({ routeTree, basepath });
Expand Down

0 comments on commit 5e876a5

Please sign in to comment.