MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / siteChecker

Function siteChecker

apps/api/src/controllers/tools.controller.ts:491–660  ·  view source on GitHub ↗
(
  request: FastifyRequest<{ Querystring: { url?: string } }>,
  reply: FastifyReply,
)

Source from the content-addressed store, hash-verified

489}
490
491export async function siteChecker(
492 request: FastifyRequest<{ Querystring: { url?: string } }>,
493 reply: FastifyReply,
494) {
495 const urlParam = request.query.url;
496
497 if (!urlParam) {
498 return reply.status(400).send({ error: 'URL parameter is required' });
499 }
500
501 const { ip } = getClientIpFromHeaders(request.headers);
502 if (ip && !checkRateLimit(`site:${ip}`, SITE_CHECK_WINDOW, SITE_CHECK_MAX)) {
503 return reply
504 .status(429)
505 .send({ error: 'Rate limit exceeded. Please try again later.' });
506 }
507
508 let url: URL;
509 try {
510 url = new URL(urlParam);
511 } catch {
512 return reply.status(400).send({ error: 'Invalid URL' });
513 }
514
515 if (!url.protocol || !url.protocol.startsWith('http')) {
516 url = new URL(`https://${urlParam}`);
517 }
518
519 try {
520 const { finalUrl, redirectChain, html, headers, statusCode, timing } =
521 await fetchWithRedirects(url.toString());
522
523 const finalUrlObj = new URL(finalUrl);
524 const $ = cheerio.load(html);
525
526 const title = $('title').first().text().trim();
527 const description =
528 $('meta[name="description"]').attr('content') ||
529 $('meta[property="og:description"]').attr('content') ||
530 '';
531 const canonical =
532 $('link[rel="canonical"]').attr('href') ||
533 $('meta[property="og:url"]').attr('content') ||
534 null;
535 const h1Tags = $('h1')
536 .map((_, el) => $(el).text().trim())
537 .get()
538 .filter(Boolean);
539 const robotsMeta =
540 $('meta[name="robots"]').attr('content') ||
541 $('meta[name="googlebot"]').attr('content') ||
542 null;
543
544 const ogTitle = $('meta[property="og:title"]').attr('content') || null;
545 const ogDescription =
546 $('meta[property="og:description"]').attr('content') || null;
547 const ogImage = $('meta[property="og:image"]').attr('content') || null;
548 const ogUrl = $('meta[property="og:url"]').attr('content') || null;

Callers

nothing calls this directly

Calls 15

getClientIpFromHeadersFunction · 0.90
getGeoLocationFunction · 0.90
checkRateLimitFunction · 0.85
fetchWithRedirectsFunction · 0.85
resolveHostnameFunction · 0.85
getIPInfoFunction · 0.85
detectCDNFunction · 0.85
getSSLInfoFunction · 0.85
checkRobotsTxtFunction · 0.85
checkSitemapFunction · 0.85
calculateSecurityScoreFunction · 0.85
sendMethod · 0.45

Tested by

no test coverage detected