Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
31 changes: 30 additions & 1 deletion src/commands/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,14 @@ async fn create_custom_domain(
Ok(())
}

pub(crate) fn format_verification_txt_value(token: &str) -> String {
if token.starts_with("railway-verify=") {
token.to_string()
} else {
format!("railway-verify={token}")
}
}

fn print_dns(
domains: Vec<
mutations::custom_domain_create::CustomDomainCreateCustomDomainCreateStatusDnsRecords,
Expand All @@ -333,7 +341,7 @@ fn print_dns(
(Some(host), Some(token)) => {
// Strip the zone suffix from the verification DNS host (e.g., "_railway-verify.example.com" -> "_railway-verify")
let host_label = host.strip_suffix(&format!(".{}", zone)).unwrap_or(host);
Some((host_label.to_string(), format!("railway-verify={}", token)))
Some((host_label.to_string(), format_verification_txt_value(token)))
}
_ => None,
}
Expand Down Expand Up @@ -410,3 +418,24 @@ fn print_dns(
);
}
}

#[cfg(test)]
mod tests {
use super::format_verification_txt_value;

#[test]
fn preserves_existing_railway_verify_prefix() {
assert_eq!(
format_verification_txt_value("railway-verify=abc123"),
"railway-verify=abc123"
);
}

#[test]
fn adds_prefix_when_token_is_bare() {
assert_eq!(
format_verification_txt_value("abc123"),
"railway-verify=abc123"
);
}
}
3 changes: 2 additions & 1 deletion src/commands/mcp/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,8 @@ impl RailwayMcp {
.unwrap_or("");
let host_label = host.strip_suffix(&format!(".{zone}")).unwrap_or(host);
output.push_str(&format!(
"\nVerification TXT record (required):\n TXT {host_label} -> railway-verify={token}\n"
"\nVerification TXT record (required):\n TXT {host_label} -> {}\n",
crate::commands::domain::format_verification_txt_value(token)
));
}
}
Expand Down