first commit

This commit is contained in:
mstfyldz
2026-05-29 23:23:50 +03:00
commit 0773e7f6f3
9 changed files with 241 additions and 0 deletions
+46
View File
@@ -0,0 +1,46 @@
import { Router, Request, Response } from "express";
import { extractNavLinks } from "../services/scraper";
export const scrapeRoute = Router();
/**
* POST /scrape
* Body: { "url": "https://firma.com" }
*
* Response:
* {
* "source": "https://firma.com",
* "count": 6,
* "links": [
* { "label": "Hakkımızda", "url": "https://firma.com/hakkimizda" },
* ...
* ]
* }
*/
scrapeRoute.post("/", async (req: Request, res: Response) => {
const { url } = req.body as { url?: string };
if (!url) {
return res.status(400).json({ error: "'url' alanı zorunlu" });
}
// Basit URL validasyonu
try { new URL(url); } catch {
return res.status(400).json({ error: "Geçersiz URL formatı" });
}
try {
const links = await extractNavLinks(url);
return res.json({
source: url,
count: links.length,
links,
});
} catch (err) {
return res.status(500).json({
error: "Link çekme başarısız",
detail: err instanceof Error ? err.message : String(err),
});
}
});