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
+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 };