Skip to content

Commit b7b4886

Browse files
committed
cli: add serve command
Allow to easily serve a mock relay locally Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent 19a1912 commit b7b4886

File tree

5 files changed

+16
-2
lines changed

5 files changed

+16
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
* js(nostr): expose `getNip05Profile` function ([Yuki Kishimoto])
117117
* js(nostr): expose missing methods to `JsCoordinate` ([Yuki Kishimoto])
118118
* js(sdk): expose `RelayPool::relays` ([Yuki Kishimoto])
119+
* cli: add `serve` command ([Yuki Kishimoto])
119120
* book: add some python examples ([RydalWater])
120121

121122
### Fixed

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.

crates/nostr-cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ rust-version.workspace = true
77
[dependencies]
88
clap = { version = "4.5", features = ["derive"] }
99
dialoguer = "0.11"
10+
nostr-relay-builder.workspace = true
1011
nostr-sdk = { workspace = true, features = ["all-nips", "lmdb"] }
1112
once_cell.workspace = true
1213
prettytable-rs = "0.10"

crates/nostr-cli/src/cli/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ pub enum CliCommand {
2727
// tor: bool,
2828
// proxy: Option<SocketAddr>,
2929
},
30+
/// Serve a local relay for test purpose
31+
Serve,
3032
/// Serve Nostr Connect signer
3133
///
3234
/// <https://github.com/nostr-protocol/nips/blob/master/46.md>

crates/nostr-cli/src/main.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::io::{BufRead, BufReader};
77
use std::time::Duration;
88

99
use clap::Parser;
10-
use cli::DatabaseCommand;
10+
use nostr_relay_builder::prelude::*;
1111
use nostr_sdk::prelude::*;
1212
use rustyline::error::ReadlineError;
1313
use rustyline::DefaultEditor;
@@ -16,7 +16,7 @@ use tokio::time::Instant;
1616
mod cli;
1717
mod util;
1818

19-
use self::cli::{io, parser, Cli, CliCommand, Command};
19+
use self::cli::{io, parser, Cli, CliCommand, Command, DatabaseCommand};
2020

2121
#[tokio::main]
2222
async fn main() {
@@ -75,6 +75,15 @@ async fn run() -> Result<()> {
7575

7676
Ok(())
7777
}
78+
CliCommand::Serve => {
79+
let mock = MockRelay::run().await?;
80+
81+
println!("Relay running at {}", mock.url());
82+
83+
loop {
84+
tokio::time::sleep(Duration::from_secs(60)).await
85+
}
86+
}
7887
CliCommand::ServeSigner => {
7988
// Ask secret key
8089
let secret_key: SecretKey = io::get_secret_key()?;

0 commit comments

Comments
 (0)