Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions crates/gitlawb-node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ pub struct Config {
#[arg(long, env = "GITLAWB_PUBLIC_URL")]
pub public_url: Option<String>,

/// Base URL for the web view of repos on this node (e.g. https://gitlawb.com).
/// When set, `GET /` advertises it as `web_url` so the CLI can print a
/// working `View:` link. Omit for nodes that have no web front-end.
#[arg(long, env = "GITLAWB_WEB_URL")]
pub web_url: Option<String>,

/// Comma-separated list of bootstrap peer URLs to announce to on startup
#[arg(long, env = "GITLAWB_BOOTSTRAP_PEERS", value_delimiter = ',')]
pub bootstrap_peers: Vec<String>,
Expand Down
15 changes: 13 additions & 2 deletions crates/gitlawb-node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ use state::AppState;
struct DegradedState {
node_did: String,
db_startup: Arc<DbStartupStatus>,
web_url: Option<String>,
}

/// Two independent counters with no cross-field invariant — atomics, not a
Expand Down Expand Up @@ -154,6 +155,7 @@ async fn main() -> Result<()> {
degraded_listener,
node_did.to_string(),
Arc::clone(&db_startup),
config.web_url.clone(),
db_ready_rx,
shutdown_tx.subscribe(),
));
Expand Down Expand Up @@ -780,11 +782,12 @@ async fn run_degraded_server(
listener: TcpListener,
node_did: String,
db_startup: Arc<DbStartupStatus>,
web_url: Option<String>,
mut db_ready_rx: watch::Receiver<bool>,
mut shutdown_rx: watch::Receiver<bool>,
) -> Result<()> {
let addr = listener.local_addr().ok();
let router = build_degraded_router(node_did, db_startup);
let router = build_degraded_router(node_did, db_startup, web_url);
info!(?addr, "degraded HTTP server ready");

axum::serve(listener, router)
Expand All @@ -801,10 +804,15 @@ async fn run_degraded_server(
Ok(())
}

fn build_degraded_router(node_did: String, db_startup: Arc<DbStartupStatus>) -> Router {
fn build_degraded_router(
node_did: String,
db_startup: Arc<DbStartupStatus>,
web_url: Option<String>,
) -> Router {
let state = DegradedState {
node_did,
db_startup,
web_url,
};
// Everything answers 503 with the same body — including /health and
// /ready, so peer readiness probes and uptime monitors correctly see a
Expand Down Expand Up @@ -836,6 +844,9 @@ async fn degraded_node_info(State(state): State<DegradedState>) -> impl IntoResp
obj.insert("name".into(), "gitlawb-node".into());
obj.insert("version".into(), env!("CARGO_PKG_VERSION").into());
obj.insert("did".into(), state.node_did.clone().into());
if let Some(web_url) = &state.web_url {
obj.insert("web_url".into(), web_url.clone().into());
}
}
(StatusCode::SERVICE_UNAVAILABLE, Json(body))
}
Expand Down
8 changes: 6 additions & 2 deletions crates/gitlawb-node/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ async fn ready(State(state): State<AppState>) -> axum::response::Response {

async fn node_info(State(state): State<AppState>) -> Json<serde_json::Value> {
let p2p_peer_id = state.p2p.as_ref().map(|h| h.local_peer_id.to_string());
Json(json!({
let mut body = json!({
"name": "gitlawb-node",
"version": env!("CARGO_PKG_VERSION"),
"did": state.node_did.to_string(),
Expand All @@ -540,7 +540,11 @@ async fn node_info(State(state): State<AppState>) -> Json<serde_json::Value> {
"auth": "http-signature-rfc9421",
"identity": "ed25519",
"p2p_peer_id": p2p_peer_id,
}))
});
if let Some(web_url) = &state.config.web_url {
body["web_url"] = json!(web_url);
}
Json(body)
}

pub(crate) async fn stats(State(state): State<AppState>) -> Json<serde_json::Value> {
Expand Down
11 changes: 10 additions & 1 deletion crates/gl/src/mirror.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,16 @@ pub async fn run(args: MirrorArgs) -> Result<()> {
println!();
println!("✓ Mirror complete: {name}");
println!(" Clone: git clone {gitlawb_url}");
println!(" View: https://gitlawb.com/{owner_short}/{name}");
// Only print View: when the node advertises a web_url — self-hosted nodes
// without a web front-end would otherwise produce a 404 link (#370).
let info_client = NodeClient::new(&args.node, None);
if let Ok(info_resp) = info_client.get("/").await {
if let Ok(info) = info_resp.json::<Value>().await {
if let Some(web_url) = info["web_url"].as_str() {
println!(" View: {web_url}/{owner_short}/{name}");
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

Ok(())
}
Expand Down
11 changes: 10 additions & 1 deletion crates/gl/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,16 @@ async fn cmd_create(
println!("✓ Created repository: {name}");
println!(" Clone: git clone {gitlawb_url}");
println!(" HTTP: {clone_url}");
println!(" View: https://gitlawb.com/{owner_short}/{name}");
// Only print View: when the node advertises a web_url — self-hosted nodes
// without a web front-end would otherwise produce a 404 link (#370).
let info_client = NodeClient::new(&node, None);
if let Ok(info_resp) = info_client.get("/").await {
if let Ok(info) = info_resp.json::<Value>().await {
if let Some(web_url) = info["web_url"].as_str() {
println!(" View: {web_url}/{owner_short}/{name}");
}
}
}
if let Some(desc) = payload["description"].as_str().filter(|s| !s.is_empty()) {
println!(" Desc: {desc}");
}
Expand Down
Loading