fix some problems with url origins in web (denoising works there too)

This commit is contained in:
2025-10-28 01:28:09 -06:00
parent 1efd32892e
commit 70634065ac
3 changed files with 16 additions and 10 deletions
+2 -1
View File
@@ -1,4 +1,5 @@
public_url = "https://127.0.0.1:4433" public_url = "https://localhost:64444"
proxy_url = "https://127.0.0.1:4433/proxy"
https_listen_address = "127.0.0.1:4433" https_listen_address = "127.0.0.1:4433"
http_listen_address = "127.0.0.1:4400" http_listen_address = "127.0.0.1:4400"
mumble_server_url = "127.0.0.1:64738" mumble_server_url = "127.0.0.1:64738"
+9 -8
View File
@@ -405,14 +405,16 @@ pub fn load_username() -> Option<String> {
.ok()? .ok()?
} }
pub fn absolute_url(path: &str) -> Result<Url, Error> {
let window: web_sys::Window = web_sys::window().expect("no global `window` exists");
let location = window.location();
Ok(Url::parse(&location.href().ey()?)?.join(path)?)
}
pub async fn load_config() -> color_eyre::Result<ClientConfig> { pub async fn load_config() -> color_eyre::Result<ClientConfig> {
let config_url = match option_env!("MUMBLE_WEB2_GUI_CONFIG_URL") { let config_url = match option_env!("MUMBLE_WEB2_GUI_CONFIG_URL") {
Some(url) => Url::parse(url)?, Some(url) => Url::parse(url)?,
None => { None => absolute_url("config")?,
let window: web_sys::Window = web_sys::window().expect("no global `window` exists");
let location = window.location();
Url::parse(&location.href().ey()?)?.join("config")?
}
}; };
info!("loading config from {}", config_url); info!("loading config from {}", config_url);
@@ -448,9 +450,8 @@ pub fn init_logging() {
// TODO: once we update to dioxus 0.7, swap this out with the dioxus-asset-resolver crate // TODO: once we update to dioxus 0.7, swap this out with the dioxus-asset-resolver crate
pub async fn read_asset_bytes(asset: &dioxus::prelude::Asset) -> color_eyre::Result<Vec<u8>> { pub async fn read_asset_bytes(asset: &dioxus::prelude::Asset) -> color_eyre::Result<Vec<u8>> {
let path = asset.to_string(); let url = absolute_url(asset.to_string().trim_matches('/'))?;
let path = path.trim_matches('/'); Ok(reqwest::get(url).await?.bytes().await?.to_vec())
Ok(reqwest::get(path).await?.bytes().await?.to_vec())
} }
pub struct SpawnHandle; pub struct SpawnHandle;
+5 -1
View File
@@ -39,6 +39,7 @@ fn default_cert_alt_names() -> Vec<String> {
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
struct Config { struct Config {
public_url: Url, public_url: Url,
proxy_url: Option<Url>,
https_listen_address: SocketAddr, https_listen_address: SocketAddr,
http_listen_address: Option<SocketAddr>, http_listen_address: Option<SocketAddr>,
cert_path: Option<PathBuf>, cert_path: Option<PathBuf>,
@@ -82,7 +83,10 @@ async fn main() -> Result<()> {
.map_err(|e| anyhow!("could not install crypto provider {e:?}"))?; .map_err(|e| anyhow!("could not install crypto provider {e:?}"))?;
let mut client_config = ClientConfig { let mut client_config = ClientConfig {
proxy_url: Some(server_config.public_url.join("proxy")?.to_string()), proxy_url: match &server_config.proxy_url {
Some(url) => Some(url.to_string()),
None => Some(server_config.public_url.join("proxy")?.to_string()),
},
status_url: Some(server_config.public_url.join("status")?.to_string()), status_url: Some(server_config.public_url.join("status")?.to_string()),
cert_hash: None, cert_hash: None,
any_server: false, any_server: false,