-
Notifications
You must be signed in to change notification settings - Fork 1
feat: configure federation status CLI for remote backend #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0ddbe9f
feat: allow federation status CLI to target remote backend
csecrestjr 8dc83eb
fix: add CLI dependencies
csecrestjr b21fd49
Merge pull request #67 from NTARI-OpenCoreLab/codex/fix-comments-in-p…
csecrestjr 8b6b128
chore: remove external deps from federation status CLI
csecrestjr d8d3868
Merge pull request #70 from NTARI-OpenCoreLab/codex/address-feedback-…
csecrestjr 120cf5b
fix: ensure federation status CLI prefers IPv4
csecrestjr b353102
Merge pull request #71 from NTARI-OpenCoreLab/codex/fix-comment-in-pa…
csecrestjr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,32 +1,30 @@ | ||
| const axios = require("axios"); | ||
| const chalk = require("chalk"); | ||
| const Table = require("cli-table3"); | ||
| const dns = require("dns"); | ||
|
|
||
| const BASE_URL = "http://localhost:5000/federation/status"; | ||
| dns.setDefaultResultOrder("ipv4first"); | ||
|
|
||
| const BASE_URL = process.env.BACKEND_URL || "http://127.0.0.1:5000"; | ||
|
|
||
| const colorize = (status) => | ||
| status === "ONLINE" ? "\x1b[32mONLINE\x1b[0m" : "\x1b[31mOFFLINE\x1b[0m"; | ||
|
|
||
| (async function () { | ||
| try { | ||
| const { data } = await axios.get(BASE_URL); | ||
| const table = new Table({ | ||
| head: ["Node URL", "Status", "Listings", "Transactions", "Users", "Last Sync"], | ||
| colWidths: [35, 10, 12, 15, 10, 25], | ||
| }); | ||
| const res = await fetch(`${BASE_URL}/federation/status`); | ||
| if (!res.ok) throw new Error(`HTTP ${res.status}`); | ||
| const data = await res.json(); | ||
|
|
||
| data.federationHealth.forEach((node) => { | ||
| const statusColor = node.status === "ONLINE" ? chalk.green : chalk.red; | ||
| table.push([ | ||
| node.node, | ||
| statusColor(node.status), | ||
| node.listings || "-", | ||
| node.transactions || "-", | ||
| node.users || "-", | ||
| node.lastSync ? new Date(node.lastSync).toLocaleString() : "N/A", | ||
| ]); | ||
| }); | ||
| const rows = data.federationHealth.map((node) => ({ | ||
| "Node URL": node.node, | ||
| Status: colorize(node.status), | ||
| Listings: node.listings || "-", | ||
| Transactions: node.transactions || "-", | ||
| Users: node.users || "-", | ||
| "Last Sync": node.lastSync ? new Date(node.lastSync).toLocaleString() : "N/A", | ||
| })); | ||
|
|
||
| console.log(chalk.bold.cyan("\n🌍 Federation Node Status Report")); | ||
| console.log(table.toString()); | ||
| console.log("\n🌍 Federation Node Status Report"); | ||
| console.table(rows); | ||
| } catch (error) { | ||
| console.error(chalk.red("Failed to fetch federation status:"), error.message); | ||
| console.error("Failed to fetch federation status:", error.message); | ||
| } | ||
| })(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.