1

This is surprisingly hard to find in the documentation. I want to use a different base_url for my API endpoint for every Cargo profile. So, —-profile=debug will use https://localhost:3000, and —-profile=release will use https://api.cooldomain.io/ or something like that.

Any pointers?

Seto
  • 1,234
  • 1
  • 17
  • 33

1 Answers1

3

You can set your base_url using #[cfg(debug_assertions)] for debug profiles and using #[cfg(not(debug_assertions))] for non debug profiles.

For example like this

#[cfg(debug_assertions)]
const BASE_URL:&'static str = "http://localhost:3000";

#[cfg(not(debug_assertions))]
const BASE_URL:&'static str = "https://api.cooldomain.io/";

fn main() {
    println!("{}",BASE_URL);
}

You can read more about debug_assertions here

Sreyas
  • 461
  • 3
  • 15