Configuring your Application
Configuration is performed within the src/config.rs file, which defines a configuration factory
function that returns a JSON object.
To customize your application build, use the env! and option_env! Rust macros to read environment
variables at build time. This will hard-code their final values into your sealed wasm bundle, ensuring
scrict release versioning and optimal security.
Configuring your Adapter
One common use case is the need to configure your application's adapters with the URL of your back-end API service. To achieve that, your configuration might look like this:
// src/config.rs
pub fn new() -> serde_json::Value {
serde_json::json!({
"api_url": option_env!("API_URL").unwrap_or("http://localhost:3000"),
})
}
or
// src/config.rs
pub fn new() -> serde_json::Value {
serde_json::json!({
"api_url": env!("API_URL").expect("an API_URL is required to build"),
})
}
At build time, you would provide the API URL during calls to make as follows for a test environment:
$ API_URL=https://api.test.yourapp.yourdomain make
or for a production environment:
$ API_URL=https://api.yourapp.yourdomain make
On application startup, adapters have their init() function invoked, which is where the config is passed
in as a parameter.