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 fs = require("fs").promises;
const path = require("path");
const urlStoreController = require("./../models/url_store_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 app = express();
+16862 -165594
View File
File diff suppressed because it is too large Load Diff
+13 -50
View File
@@ -1,52 +1,15 @@
[
"cloudflare.com",
"Akshay",
"postgresql.org",
"http://localhost:3001",
"invalid-url.com",
"github.com",
"random-string",
"mozilla.org",
"todo",
"amazon.com",
"unknown-host-999.com",
"google.com",
"hello world",
"docker.com",
"abc123invalid.org",
"wikipedia.org",
"http://localhost:99999",
"duckduckgo.com",
"myfakeportal.dev",
"nodejs.org",
"example.com",
"ftp://example.com",
"bing.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"
"cloudflare.com",
"postgresql.org",
"github.com",
"mozilla.org",
"amazon.com",
"google.com",
"docker.com",
"wikipedia.org",
"duckduckgo.com",
"nodejs.org",
"amns.in",
"amazon.in",
"amdocs.com"
]
+2 -1
View File
@@ -1,5 +1,6 @@
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) => {
try {
+1 -6
View File
@@ -1,6 +1,5 @@
const axios = require("axios");
const fs = require("fs").promises;
const path = require("path");
const normalizeUrl = require("../utils/utils").normalizeUrl;
async function checkUrl(url) {
@@ -8,11 +7,7 @@ async function checkUrl(url) {
try {
const start = Date.now();
const response = await axios.get(target, {
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",
},
timeout: 10000
});
const responseTime = Date.now() - start;
+2 -1
View File
@@ -1,5 +1,6 @@
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) => {
try {
+12 -25
View File
@@ -1,16 +1,16 @@
const axios = require("axios");
const fs = require("fs").promises;
const dotenv = require("dotenv");
const path = require("path");
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 = "./database/urls.json";
const urlPath = path.join(__dirname, "database", "urls.json");
dotenv.config();
async function setupWebSocket(wss) {
init(wss);
let Store = [];
const checkAllUrl = async (Store) => {
try {
const urls = await fs.readFile(urlPath, "utf8");
const parsedUrls = JSON.parse(urls);
@@ -31,28 +31,15 @@ async function setupWebSocket(wss) {
message: "Unable to read urls.json or parse data",
});
}
};
async function setupWebSocket(wss) {
init(wss);
let Store = [];
checkAllUrl(Store);
setInterval(async () => {
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",
});
}
}, process.env.TIME || 60000);
Store = [];
checkAllUrl(Store);
}, 2000);
}
module.exports = { setupWebSocket };
+2 -1
View File
@@ -2,8 +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": "index.js",
"main": "app.js",
"scripts": {
"start": "node backend/app.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],