improvement for deplyment to cloud

This commit is contained in:
Vadher
2026-07-19 15:48:57 +05:30
parent b4c54c0309
commit 803efec35a
8 changed files with 16897 additions and 165682 deletions
+2 -3
View File
@@ -1,10 +1,9 @@
const express = require("express"); const express = require("express");
const fs = require("fs").promises; const fs = require("fs").promises;
const path = require("path");
const urlStoreController = require("./../models/url_store_controller"); const urlStoreController = require("./../models/url_store_controller");
const healthStatusController = require("./../models/health_status_controller"); const healthStatusController = require("./../models/health_status_controller");
const urlPath = "./database/urls.json"; const urlPath = path.join(__dirname, "../database", "urls.json");
const router = express.Router(); const router = express.Router();
const app = express(); const app = express();
+16910 -165642
View File
File diff suppressed because it is too large Load Diff
+3 -40
View File
@@ -1,52 +1,15 @@
[ [
"cloudflare.com", "cloudflare.com",
"Akshay",
"postgresql.org", "postgresql.org",
"http://localhost:3001",
"invalid-url.com",
"github.com", "github.com",
"random-string",
"mozilla.org", "mozilla.org",
"todo",
"amazon.com", "amazon.com",
"unknown-host-999.com",
"google.com", "google.com",
"hello world",
"docker.com", "docker.com",
"abc123invalid.org",
"wikipedia.org", "wikipedia.org",
"http://localhost:99999",
"duckduckgo.com", "duckduckgo.com",
"myfakeportal.dev",
"nodejs.org", "nodejs.org",
"example.com", "amns.in",
"ftp://example.com", "amazon.in",
"bing.com", "amdocs.com"
"thissitedoesnotexist123456.com",
"mongodb.com",
"12345",
"reddit.com",
"openai.com",
"https://",
"netflix.com",
"expressjs.com",
"ubuntu.org",
"test-invalid-domain.local",
"microsoft.com",
"http://localhost:8080",
"www.",
"yahoo.com",
"vercel.com",
"brokenwebsite.fake",
"golang.org",
"apple.com",
"digitalocean.com",
"://invalid",
"python.org",
"notarealwebsite987654.io",
"fake-company-xyz.net",
"ubuntu.com",
"stackoverflow.com",
"idontexist.xyz",
"npmjs.com"
] ]
+2 -1
View File
@@ -1,5 +1,6 @@
const fs = require("node:fs").promises; const fs = require("node:fs").promises;
const url_path = "./database/db.json"; const path = require("path");
const url_path = path.join(__dirname, "../database", "db.json");
const StoreRecord = async (urlRecord) => { const StoreRecord = async (urlRecord) => {
try { try {
+1 -6
View File
@@ -1,6 +1,5 @@
const axios = require("axios"); const axios = require("axios");
const fs = require("fs").promises; const fs = require("fs").promises;
const path = require("path");
const normalizeUrl = require("../utils/utils").normalizeUrl; const normalizeUrl = require("../utils/utils").normalizeUrl;
async function checkUrl(url) { async function checkUrl(url) {
@@ -8,11 +7,7 @@ async function checkUrl(url) {
try { try {
const start = Date.now(); const start = Date.now();
const response = await axios.get(target, { const response = await axios.get(target, {
timeout: 10000, timeout: 10000
headers: {
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0 Safari/537.36",
},
}); });
const responseTime = Date.now() - start; const responseTime = Date.now() - start;
+2 -1
View File
@@ -1,5 +1,6 @@
const fs = require("node:fs").promises; const fs = require("node:fs").promises;
const url_path = "./database/urls.json"; const path = require("path");
const url_path = path.join(__dirname, "../database", "urls.json");
const addUrl = async (url) => { const addUrl = async (url) => {
try { try {
+29 -42
View File
@@ -1,58 +1,45 @@
const axios = require("axios"); const axios = require("axios");
const fs = require("fs").promises; const fs = require("fs").promises;
const dotenv = require("dotenv"); const dotenv = require("dotenv");
const path = require("path");
const { StoreRecord } = require("./models/db_store_controller"); const { StoreRecord } = require("./models/db_store_controller");
const { checkUrl } = require("./models/health_status_controller"); const { checkUrl } = require("./models/health_status_controller");
const { init, broadcast } = require("./utils/utils"); const { init, broadcast } = require("./utils/utils");
const urlPath = "./database/urls.json"; // const urlPath = "./database/urls.json";
const urlPath = path.join(__dirname, "database", "urls.json");
dotenv.config(); dotenv.config();
const checkAllUrl = async (Store) => {
try {
const urls = await fs.readFile(urlPath, "utf8");
const parsedUrls = JSON.parse(urls);
await Promise.allSettled(
parsedUrls.map(async (url) => {
const response = await checkUrl(url);
broadcast(response);
Store.push(response);
}),
);
StoreRecord(Store);
broadcast({ type: "checking" });
} catch (err) {
console.error("WebSocket polling error:", err.message);
broadcast({
type: "error",
message: "Unable to read urls.json or parse data",
});
}
};
async function setupWebSocket(wss) { async function setupWebSocket(wss) {
init(wss); init(wss);
let Store = []; let Store = [];
try { checkAllUrl(Store);
const urls = await fs.readFile(urlPath, "utf8");
const parsedUrls = JSON.parse(urls);
await Promise.allSettled(
parsedUrls.map(async (url) => {
const response = await checkUrl(url);
broadcast(response);
Store.push(response);
}),
);
StoreRecord(Store);
broadcast({ type: "checking" });
} catch (err) {
console.error("WebSocket polling error:", err.message);
broadcast({
type: "error",
message: "Unable to read urls.json or parse data",
});
}
setInterval(async () => { setInterval(async () => {
try { Store = [];
const urls = await fs.readFile(urlPath, "utf8"); checkAllUrl(Store);
const parsedUrls = JSON.parse(urls); }, 2000);
await Promise.allSettled(
parsedUrls.map(async (url) => {
const response = await checkUrl(url);
broadcast(response);
Store.push(response);
}),
);
StoreRecord(Store);
broadcast({ type: "checking" });
} catch (err) {
console.error("WebSocket polling error:", err.message);
broadcast({
type: "error",
message: "Unable to read urls.json or parse data",
});
}
}, process.env.TIME || 60000);
} }
module.exports = { setupWebSocket }; module.exports = { setupWebSocket };
+2 -1
View File
@@ -2,8 +2,9 @@
"name": "uptime_monitor", "name": "uptime_monitor",
"version": "1.0.0", "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.", "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": "index.js", "main": "app.js",
"scripts": { "scripts": {
"start": "node backend/app.js",
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"keywords": [], "keywords": [],