Skip to content

Commit 4509db6

Browse files
feat: add api-public-url parameter (#153)
1 parent 35590d4 commit 4509db6

File tree

7 files changed

+37
-20
lines changed

7 files changed

+37
-20
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 0.12.1 (2025-11-11)
4+
5+
- Added `api-public-url` CLI param to fix the backend and frontend communication ([#153](https://github.com/0xMiden/miden-faucet/pull/153)).
6+
37
## 0.12.0 (2025-11-10)
48

59
- Added requested `amount` to PoW Challenge ([#68](https://github.com/0xMiden/miden-faucet/pull/68)).
@@ -12,7 +16,7 @@
1216
- Separated frontend and backend servers ([#119](https://github.com/0xMiden/miden-faucet/pull/119)).
1317
- Frontend now awaits for the transaction to be committed ([#127](https://github.com/0xMiden/miden-faucet/pull/127)).
1418
- Added 10-block expiration delta to faucet minting transactions ([#136](https://github.com/0xMiden/miden-faucet/pull/136)).
15-
-
19+
1620
## 0.11.8 (2025-10-27)
1721

1822
- Sync state before creating transactions to avoid desync errors (#[132](https://github.com/0xMiden/miden-faucet/pull/132)).

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ license = "MIT"
1212
readme = "README.md"
1313
repository = "https://github.com/0xMiden/miden-faucet"
1414
rust-version = "1.90"
15-
version = "0.12.0"
15+
version = "0.12.1"
1616

1717
# Optimize the cryptography for faster tests involving account creation.
1818
[profile.test.package.miden-crypto]

bin/faucet/.env

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ MIDEN_FAUCET_MAX_SUPPLY=
1313

1414
# Faucet Service Configuration
1515
MIDEN_FAUCET_FRONTEND_URL=http://0.0.0.0:8080
16-
MIDEN_FAUCET_API_URL=http://0.0.0.0:8000
16+
MIDEN_FAUCET_API_BIND_URL=http://0.0.0.0:8000
17+
MIDEN_FAUCET_API_PUBLIC_URL=
1718
MIDEN_FAUCET_MAX_CLAIMABLE_AMOUNT=
1819
MIDEN_FAUCET_ENABLE_OTEL=false
1920
MIDEN_FAUCET_BASE_AMOUNT=

bin/faucet/src/frontend.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ use url::Url;
1313
use crate::COMPONENT;
1414

1515
/// Serves the frontend API endpoints.
16-
pub async fn serve_frontend(url: Url, api_url: Url, node_url: String) -> anyhow::Result<()> {
16+
pub async fn serve_frontend(url: Url, api_public_url: Url, node_url: String) -> anyhow::Result<()> {
1717
let config_json = Json(
1818
serde_json::json!({
19-
"api_url": api_url.to_string().trim_end_matches('/'),
19+
"api_url": api_public_url.to_string().trim_end_matches('/'),
2020
"node_url": node_url.trim_end_matches('/'),
2121
})
2222
.to_string(),

bin/faucet/src/main.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ use crate::network::FaucetNetwork;
4949
pub const REQUESTS_QUEUE_SIZE: usize = 1000;
5050
const COMPONENT: &str = "miden-faucet-server";
5151

52-
const ENV_API_URL: &str = "MIDEN_FAUCET_API_URL";
52+
const ENV_API_BIND_URL: &str = "MIDEN_FAUCET_API_BIND_URL";
53+
const ENV_API_PUBLIC_URL: &str = "MIDEN_FAUCET_API_PUBLIC_URL";
5354
const ENV_FRONTEND_URL: &str = "MIDEN_FAUCET_FRONTEND_URL";
5455
const ENV_NETWORK: &str = "MIDEN_FAUCET_NETWORK";
5556
const ENV_NODE_URL: &str = "MIDEN_FAUCET_NODE_URL";
@@ -129,12 +130,15 @@ pub enum Command {
129130
#[clap(flatten)]
130131
config: ClientConfig,
131132

132-
/// API URL, in the format `<ip>:<port>`.
133-
#[arg(long = "api-url", value_name = "URL", env = ENV_API_URL)]
134-
api_url: Url,
133+
/// URL to bind the API server.
134+
#[arg(long = "api-bind-url", value_name = "URL", env = ENV_API_BIND_URL)]
135+
api_bind_url: Url,
135136

136-
/// Frontend API URL, in the format `<ip>:<port>`. If not set, the frontend will not be
137-
/// served.
137+
/// Public URL to access the API server. If not set, the bind url will be used.
138+
#[arg(long = "api-public-url", value_name = "URL", env = ENV_API_PUBLIC_URL)]
139+
api_public_url: Option<Url>,
140+
141+
/// URL to bind the frontend server. If not set, the frontend will not be served.
138142
#[arg(long = "frontend-url", value_name = "URL", env = ENV_FRONTEND_URL)]
139143
frontend_url: Option<Url>,
140144

@@ -324,7 +328,8 @@ async fn run_faucet_command(cli: Cli) -> anyhow::Result<()> {
324328
network,
325329
store_path,
326330
},
327-
api_url,
331+
api_bind_url,
332+
api_public_url,
328333
frontend_url,
329334
max_claimable_amount,
330335
pow_secret,
@@ -402,12 +407,16 @@ async fn run_faucet_command(cli: Cli) -> anyhow::Result<()> {
402407
let mut tasks = JoinSet::new();
403408
let mut tasks_ids = HashMap::new();
404409

405-
let api_id = tasks.spawn(api_server.serve(api_url.clone())).id();
410+
let api_id = tasks.spawn(api_server.serve(api_bind_url.clone())).id();
406411
tasks_ids.insert(api_id, "api");
407412

408413
if let Some(frontend_url) = frontend_url {
409414
let frontend_id = tasks
410-
.spawn(serve_frontend(frontend_url, api_url, node_endpoint.to_string()))
415+
.spawn(serve_frontend(
416+
frontend_url,
417+
api_public_url.unwrap_or(api_bind_url),
418+
node_endpoint.to_string(),
419+
))
411420
.id();
412421
tasks_ids.insert(frontend_id, "frontend");
413422
}
@@ -628,7 +637,8 @@ mod tests {
628637
Box::pin(run_faucet_command(Cli {
629638
command: crate::Command::Start {
630639
config,
631-
api_url: Url::try_from(api_url).unwrap(),
640+
api_bind_url: Url::try_from(api_url).unwrap(),
641+
api_public_url: None,
632642
frontend_url: Some(Url::parse(frontend_url).unwrap()),
633643
max_claimable_amount: 1_000_000_000,
634644
api_keys: vec![],

docs/src/getting-started/cli.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ miden-faucet start \
6464

6565
| Option | Description | Default | Required |
6666
|--------|-------------|---------|----------|
67-
| `--api-url` | URL to serve the faucet API | - | Yes |
67+
| `--api-bind-url` | URL to serve the faucet API | - | Yes |
68+
| `--api-public-url` | Public URL to access the faucet API. If not set, the bind url will be used. | - | No |
6869
| `--frontend-url` | URL to serve the Frontend API | - | No |
6970
| `--node-url` | Miden node RPC endpoint. If not set, it will be derived from the network | - | No |
7071
| `--network` | Network configuration | `localhost` | No |
@@ -107,7 +108,8 @@ export MIDEN_FAUCET_MAX_SUPPLY=
107108

108109
# Faucet Service Configuration
109110
export MIDEN_FAUCET_FRONTEND_URL=http://localhost:8080
110-
export MIDEN_FAUCET_API_URL=http://localhost:8000
111+
export MIDEN_FAUCET_API_BIND_URL=http://localhost:8000
112+
export MIDEN_FAUCET_API_PUBLIC_URL=http://localhost:8000
111113
export MIDEN_FAUCET_MAX_CLAIMABLE_AMOUNT=1000000000
112114
export MIDEN_FAUCET_ENABLE_OTEL=true
113115
export MIDEN_FAUCET_BASE_AMOUNT=100000000

0 commit comments

Comments
 (0)