improvement for deplyment to cloud
This commit is contained in:
@@ -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();
|
||||||
|
|
||||||
|
|||||||
+16862
-165594
File diff suppressed because it is too large
Load Diff
+13
-50
@@ -1,52 +1,15 @@
|
|||||||
[
|
[
|
||||||
"cloudflare.com",
|
"cloudflare.com",
|
||||||
"Akshay",
|
"postgresql.org",
|
||||||
"postgresql.org",
|
"github.com",
|
||||||
"http://localhost:3001",
|
"mozilla.org",
|
||||||
"invalid-url.com",
|
"amazon.com",
|
||||||
"github.com",
|
"google.com",
|
||||||
"random-string",
|
"docker.com",
|
||||||
"mozilla.org",
|
"wikipedia.org",
|
||||||
"todo",
|
"duckduckgo.com",
|
||||||
"amazon.com",
|
"nodejs.org",
|
||||||
"unknown-host-999.com",
|
"amns.in",
|
||||||
"google.com",
|
"amazon.in",
|
||||||
"hello world",
|
"amdocs.com"
|
||||||
"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"
|
|
||||||
]
|
]
|
||||||
@@ -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 +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;
|
||||||
|
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
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();
|
||||||
|
|
||||||
async function setupWebSocket(wss) {
|
const checkAllUrl = async (Store) => {
|
||||||
init(wss);
|
|
||||||
let Store = [];
|
|
||||||
try {
|
try {
|
||||||
const urls = await fs.readFile(urlPath, "utf8");
|
const urls = await fs.readFile(urlPath, "utf8");
|
||||||
const parsedUrls = JSON.parse(urls);
|
const parsedUrls = JSON.parse(urls);
|
||||||
@@ -31,28 +31,15 @@ async function setupWebSocket(wss) {
|
|||||||
message: "Unable to read urls.json or parse data",
|
message: "Unable to read urls.json or parse data",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
async function setupWebSocket(wss) {
|
||||||
|
init(wss);
|
||||||
|
let Store = [];
|
||||||
|
checkAllUrl(Store);
|
||||||
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
@@ -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": [],
|
||||||
|
|||||||
Reference in New Issue
Block a user