Fix logging and robots.txt

This commit is contained in:
gpt-engineer-app[bot]
2025-11-04 22:01:27 +00:00
parent 40ebc3c11b
commit ffd71f51fb
3 changed files with 71 additions and 14 deletions

View File

@@ -15,6 +15,7 @@ type VercelResponse = ServerResponse & {
};
import { detectBot } from './botDetection/index.js';
import { vercelLogger } from './utils/logger.js';
interface PageData {
title: string;
@@ -76,7 +77,10 @@ async function getPageData(pathname: string, fullUrl: string): Promise<PageData>
}
}
} catch (error) {
console.error(`[SSR-OG] Error fetching park data: ${error}`);
vercelLogger.error('Error fetching park data', {
error: error instanceof Error ? error.message : String(error),
slug
});
}
}
@@ -115,7 +119,10 @@ async function getPageData(pathname: string, fullUrl: string): Promise<PageData>
}
}
} catch (error) {
console.error(`[SSR-OG] Error fetching ride data: ${error}`);
vercelLogger.error('Error fetching ride data', {
error: error instanceof Error ? error.message : String(error),
slug: rideSlug
});
}
}
@@ -204,20 +211,29 @@ export default async function handler(req: VercelRequest, res: VercelResponse):
// Enhanced logging with detection details
if (botDetection.isBot) {
console.log(`[SSR-OG] ✅ Bot detected: ${botDetection.platform || 'unknown'} | Confidence: ${botDetection.confidence} (${botDetection.score}%) | Method: ${botDetection.detectionMethod}`);
console.log(`[SSR-OG] Path: ${req.method} ${pathname}`);
console.log(`[SSR-OG] UA: ${userAgent}`);
if (botDetection.metadata.signals.length > 0) {
console.log(`[SSR-OG] Signals: ${botDetection.metadata.signals.slice(0, 5).join(', ')}${botDetection.metadata.signals.length > 5 ? '...' : ''}`);
}
vercelLogger.info('Bot detected', {
platform: botDetection.platform || 'unknown',
confidence: botDetection.confidence,
score: botDetection.score,
method: botDetection.detectionMethod,
path: `${req.method} ${pathname}`,
userAgent,
signals: botDetection.metadata.signals.slice(0, 5)
});
} else {
// Log potential false negatives
if (botDetection.score > 30) {
console.warn(`[SSR-OG] ⚠️ Low confidence bot (${botDetection.score}%) - not serving SSR | ${req.method} ${pathname}`);
console.warn(`[SSR-OG] UA: ${userAgent}`);
console.warn(`[SSR-OG] Signals: ${botDetection.metadata.signals.join(', ')}`);
vercelLogger.warn('Low confidence bot - not serving SSR', {
score: botDetection.score,
path: `${req.method} ${pathname}`,
userAgent,
signals: botDetection.metadata.signals
});
} else {
console.log(`[SSR-OG] Regular user (score: ${botDetection.score}%) | ${req.method} ${pathname}`);
vercelLogger.info('Regular user request', {
score: botDetection.score,
path: `${req.method} ${pathname}`
});
}
}
@@ -228,7 +244,10 @@ export default async function handler(req: VercelRequest, res: VercelResponse):
if (botDetection.isBot) {
// Fetch page-specific data
const pageData = await getPageData(pathname, fullUrl);
console.log(`[SSR-OG] Generated OG tags: ${pageData.title}`);
vercelLogger.info('Generated OG tags', {
title: pageData.title,
pathname
});
// Generate and inject OG tags
const ogTags = generateOGTags(pageData);
@@ -246,7 +265,10 @@ export default async function handler(req: VercelRequest, res: VercelResponse):
res.status(200).send(html);
} catch (error) {
console.error('[SSR-OG] Error:', error);
vercelLogger.error('SSR processing failed', {
error: error instanceof Error ? error.message : String(error),
pathname
});
// Fallback: serve original HTML
try {