improvement
This commit is contained in:
+1916
-18690
File diff suppressed because it is too large
Load Diff
@@ -1,15 +1,24 @@
|
||||
[
|
||||
"cloudflare.com",
|
||||
"postgresql.org",
|
||||
"github.com",
|
||||
"mozilla.org",
|
||||
"amazon.com",
|
||||
"example.invalid",
|
||||
"google.com",
|
||||
"myfakewebsite123.xyz",
|
||||
"postgresql.org",
|
||||
"notarealdomain.test",
|
||||
"github.com",
|
||||
"docker.com",
|
||||
"wikipedia.org",
|
||||
"duckduckgo.com",
|
||||
"nodejs.org",
|
||||
"amns.in",
|
||||
"invalid-site-999.com",
|
||||
"mozilla.org",
|
||||
"amazon.in",
|
||||
"amdocs.com"
|
||||
"thisdoesnotexistabc123.com",
|
||||
"nodejs.org",
|
||||
"amdocs.com",
|
||||
"fake-company-domain.org",
|
||||
"wikipedia.org",
|
||||
"nonexistentdomain987654.net",
|
||||
"duckduckgo.com",
|
||||
"amazon.com",
|
||||
"amns.in",
|
||||
"missingwebsite.fake",
|
||||
"randominvaliddomain12345.io"
|
||||
]
|
||||
@@ -4,6 +4,12 @@ const url_path = path.join(__dirname, "../database", "db.json");
|
||||
|
||||
const StoreRecord = async (urlRecord) => {
|
||||
try {
|
||||
try {
|
||||
await fs.access(url_path);
|
||||
} catch {
|
||||
await fs.writeFile(url_path, "[]");
|
||||
}
|
||||
|
||||
const rawData = await fs.readFile(url_path, "utf8");
|
||||
const data = JSON.parse(rawData);
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ const { StoreRecord } = require("./models/db_store_controller");
|
||||
const { checkUrl } = require("./models/health_status_controller");
|
||||
|
||||
const { init, broadcast } = require("./utils/utils");
|
||||
// const urlPath = "./database/urls.json";
|
||||
const urlPath = path.join(__dirname, "database", "urls.json");
|
||||
dotenv.config();
|
||||
|
||||
@@ -35,11 +34,17 @@ const checkAllUrl = async (Store) => {
|
||||
async function setupWebSocket(wss) {
|
||||
init(wss);
|
||||
let Store = [];
|
||||
wss.on("connection", (ws) => {
|
||||
checkAllUrl(Store);
|
||||
setInterval(async () => {
|
||||
});
|
||||
|
||||
setInterval(
|
||||
async () => {
|
||||
Store = [];
|
||||
checkAllUrl(Store);
|
||||
}, 2000);
|
||||
},
|
||||
process.env.TIME || 60 * 1000,
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = { setupWebSocket };
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
<h1>URL HEALTH MONITOR</h1>
|
||||
|
||||
<h4>WebSocket: <span id="websocket_status">Connecting...</span></h4>
|
||||
<h4>Page will fetch latest update every 60 second </h4>
|
||||
|
||||
<h4 id="status"></h4>
|
||||
</div>
|
||||
|
||||
+7
-10
@@ -11,7 +11,6 @@ async function init() {
|
||||
const urls = await response.json();
|
||||
|
||||
urls.forEach((url) => {
|
||||
|
||||
const id = url.replace(/[^a-zA-Z0-9]/g, "_");
|
||||
|
||||
const row = document.createElement("tr");
|
||||
@@ -27,7 +26,6 @@ async function init() {
|
||||
|
||||
tbody.appendChild(row);
|
||||
});
|
||||
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
@@ -45,29 +43,28 @@ const websocket_status = document.getElementById("websocket_status");
|
||||
socket.onopen = () => {
|
||||
websocket_status.textContent = "Connected";
|
||||
};
|
||||
let counter = 0
|
||||
let counter = 0;
|
||||
socket.onmessage = (event) => {
|
||||
// console.log(counter)
|
||||
const data = JSON.parse(event.data);
|
||||
if (data.type === "checking") {
|
||||
counter = counter + 1
|
||||
console.log(counter)
|
||||
document.getElementById("status").textContent = "Refreshed " + counter + " Times";
|
||||
counter = counter + 1;
|
||||
document.getElementById("status").textContent =
|
||||
"Refreshed " + counter + " Times";
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const id = data.url.replace(/[^a-zA-Z0-9]/g, "_");
|
||||
const row = document.getElementById(id);
|
||||
if (!row) return;
|
||||
|
||||
row.querySelector(".status").textContent = data.status;
|
||||
row.querySelector(".statusCode").textContent = data.statusCode;
|
||||
row.querySelector(".responseTime").textContent = data.responseTime != null ? `${data.responseTime} ms` : "-";
|
||||
row.querySelector(".responseTime").textContent =
|
||||
data.responseTime != null ? `${data.responseTime} ms` : "-";
|
||||
row.querySelector(".error").textContent = data.error || "-";
|
||||
};
|
||||
|
||||
|
||||
socket.onclose = () => {
|
||||
websocket_status.textContent = "Disconnected";
|
||||
};
|
||||
@@ -79,7 +76,7 @@ document.getElementById("addBtn").addEventListener("click", async () => {
|
||||
const response = await fetch("/api/url/register", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ url })
|
||||
body: JSON.stringify({ url }),
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
|
||||
+2
-3
@@ -2,10 +2,9 @@
|
||||
"name": "uptime_monitor",
|
||||
"version": "1.0.0",
|
||||
"description": "A lightweight **URL Health Monitoring** application built with **Node.js, Express, WebSocket, Axios, and Docker**. The application periodically checks the health of registered URLs and updates the frontend in real time using WebSockets.",
|
||||
"main": "app.js",
|
||||
"main": "./backend/app.js",
|
||||
"scripts": {
|
||||
"start": "node backend/app.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
"start": "node backend/app.js"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "Akshay Vadher",
|
||||
|
||||
Reference in New Issue
Block a user