Skip to content
Merged
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
3 changes: 2 additions & 1 deletion FEDERATION_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ Features:
How to run:
```bash
cd frontend
node federationStatusCLI.js
node federationStatusCLI.js # defaults to http://localhost:5000
BACKEND_URL=https://api.example.com node federationStatusCLI.js
```

You’ll see a report like:
Expand Down
1 change: 1 addition & 0 deletions amplify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ frontend:
build:
commands:
- npm run build
- BACKEND_URL=$BACKEND_URL node ../federationStatusCLI.js
artifacts:
baseDirectory: frontend/chat-ui/dist
files:
Expand Down
44 changes: 21 additions & 23 deletions frontend/federationStatusCLI.js
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);
}
})();
4 changes: 3 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"build": "next build",
"start": "next start",
"lint": "next lint",
"test": "next build"
"test": "next build",
"federation-status": "node federationStatusCLI.js",
"federation-status:ci": "BACKEND_URL=$BACKEND_URL node federationStatusCLI.js"
},
"dependencies": {
"next": "14.1.0",
Comment thread
csecrestjr marked this conversation as resolved.
Expand Down