Skip to content

Commit 29aaa71

Browse files
fix(front): use location host to make calls to the api
1 parent 51f0711 commit 29aaa71

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

front/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ serde = { workspace = true }
1616
uuid = { workspace = true }
1717
log = "0.4.19"
1818
wasm-logger = "0.2.0"
19+
web-sys = "0.3.64"

front/src/main.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,19 @@ use dioxus::prelude::*;
88
use models::FilmModalVisibility;
99
use shared::models::Film;
1010

11-
// const HOST: &str = "https://devbcn.shuttleapp.rs/api/v1";
12-
const HOST: &str = "http://localhost:5000/api/v1";
11+
const API_ENDPOINT: &str = "api/v1";
1312

1413
fn films_endpoint() -> String {
15-
format!("{}/films", HOST)
14+
let window = web_sys::window().expect("no global `window` exists");
15+
let location = window.location();
16+
let host = location.host().expect("should have a host");
17+
let protocol = location.protocol().expect("should have a protocol");
18+
let endpoint = format!("{}//{}/{}", protocol, host, API_ENDPOINT);
19+
format!("{}/films", endpoint)
1620
}
1721

1822
async fn get_films() -> Vec<Film> {
23+
log::info!("Getting films {}", films_endpoint());
1924
reqwest::get(&films_endpoint())
2025
.await
2126
.unwrap()

0 commit comments

Comments
 (0)