14a32bdc0d
- Unified monorepo with backend (Express), frontend (Next.js), and devops - Backend: ESLint, Prettier, Jest tests (3 passing), health endpoint, .env.example - Frontend: Fixed build errors, fixed all lint errors (0 remaining), tests passing - DevOps: Docker Compose with PostgreSQL, backend, frontend + healthchecks - CI/CD: 3 GitHub Actions workflows (backend, frontend, docker integration) - DX: Husky pre-commit hooks with smart change detection - Docs: Root README with architecture, CONTRIBUTING.md, PR template Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
95 lines
2.3 KiB
TypeScript
95 lines
2.3 KiB
TypeScript
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();
|