refactor: flatten monorepo structure to backend/ frontend/ devops/
Rename subdirectories for a cleaner single-repo layout: - website-monitoring-backend/ → backend/ - website-monitoring-frontend/ → frontend/ - website-monitoring-devops/ → devops/ Update all references in package.json scripts, CI workflows, docker-compose, pre-commit hooks, and documentation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
import { createClient } from "@supabase/supabase-js";
|
||||
import { launch } from "chrome-launcher";
|
||||
import lighthouse from "lighthouse";
|
||||
import dotenv from "dotenv";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const supabase = createClient(
|
||||
process.env.SUPABASE_URL!,
|
||||
process.env.SUPABASE_SERVICE_KEY!,
|
||||
);
|
||||
|
||||
async function main() {
|
||||
// 1. Hole alle offenen Scans
|
||||
const { data: scans, error: scanError } = await supabase
|
||||
.from("scans")
|
||||
.select("id, page_id")
|
||||
.eq("status", "pending");
|
||||
|
||||
if (scanError) {
|
||||
console.error("Fehler beim Laden der Scans:", scanError);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
for (const scan of scans ?? []) {
|
||||
try {
|
||||
// 2. Hole die URL der Seite
|
||||
const { data: page, error: pageError } = await supabase
|
||||
.from("pages")
|
||||
.select("url")
|
||||
.eq("id", scan.page_id)
|
||||
.single();
|
||||
|
||||
if (pageError || !page) {
|
||||
console.error("Fehler beim Laden der Seite:", pageError);
|
||||
continue;
|
||||
}
|
||||
|
||||
// 3. Setze Scan-Status auf "running"
|
||||
await supabase
|
||||
.from("scans")
|
||||
.update({ status: "running" })
|
||||
.eq("id", scan.id);
|
||||
|
||||
// 4. Starte Lighthouse
|
||||
const chrome = await launch({
|
||||
chromeFlags: ["--headless", "--no-sandbox", "--disable-dev-shm-usage"],
|
||||
});
|
||||
|
||||
const runnerResult = await lighthouse(page.url, {
|
||||
port: chrome.port,
|
||||
output: "json",
|
||||
logLevel: "info",
|
||||
onlyCategories: [
|
||||
"performance",
|
||||
"seo",
|
||||
"accessibility",
|
||||
"best-practices",
|
||||
],
|
||||
});
|
||||
|
||||
await chrome.kill();
|
||||
|
||||
if (!runnerResult) throw new Error("Lighthouse returned no result");
|
||||
|
||||
// 5. Speichere Ergebnisse
|
||||
await supabase.from("scan_results").insert([
|
||||
{
|
||||
scan_id: scan.id,
|
||||
raw_data: runnerResult.lhr,
|
||||
},
|
||||
]);
|
||||
|
||||
// 6. Setze Scan-Status auf "completed"
|
||||
await supabase
|
||||
.from("scans")
|
||||
.update({ status: "completed" })
|
||||
.eq("id", scan.id);
|
||||
|
||||
console.log(`Scan für ${page.url} abgeschlossen.`);
|
||||
} catch (error) {
|
||||
console.error("Scan-Fehler:", error);
|
||||
await supabase
|
||||
.from("scans")
|
||||
.update({
|
||||
status: "failed",
|
||||
error_message: error instanceof Error ? error.message : String(error),
|
||||
})
|
||||
.eq("id", scan.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user