Skip to content

Commit

Permalink
fix: add base uri
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyrix126 committed May 30, 2024
1 parent f24af57 commit 48e012c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ struct Config {
#[derive(Clone)]
struct AppState {
client: Client,
base_uri: Url,
}

impl Default for Config {
fn default() -> Self {
Self {
listen_address: Ipv4Addr::new(127, 0, 0, 1),
listen_port: 8080,
api_url: Url::parse("https://xmrchain.net/api").expect(
api_url: Url::parse("https://127.0.0.1:8081").expect(
"the url provided for api_url in the configuration file does not sem to be valid.",
),
}
Expand All @@ -42,6 +43,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
info!("creating client");
let state = AppState {
client: Client::new(),
base_uri: config.api_url.to_owned(),
};
let route = Router::new().fallback(handler).with_state(state);
let listener =
Expand All @@ -60,7 +62,10 @@ async fn handler(State(state): State<AppState>, request: Request) -> impl IntoRe
debug!("The request received {:?}", request);
let req = state
.client
.request(request.method().to_owned(), request.uri().to_string())
.request(
request.method().to_owned(),
format!("{}{}", state.base_uri, request.uri()),
)
.headers(request.headers().to_owned())
.body(to_bytes(request.into_body(), usize::MAX).await.unwrap())
.send()
Expand Down

0 comments on commit 48e012c

Please sign in to comment.