Skip to content

Commit 12a8d75

Browse files
committed
add: user agent logging for debugging AI client detection
- Log all user agents for non-static requests - Log when redirects to markdown occur - Helps identify what user agents AI tools are sending
1 parent 5df8a41 commit 12a8d75

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/middleware.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ const handleAIClientRedirect = (request: NextRequest) => {
5959
const userAgent = request.headers.get('user-agent') || '';
6060
const url = request.nextUrl;
6161

62+
// Log user agent for debugging (only for non-static assets)
63+
if (!url.pathname.startsWith('/_next/') &&
64+
!url.pathname.includes('.') &&
65+
!url.pathname.startsWith('/api/')) {
66+
console.log(`[Middleware] ${url.pathname} - User-Agent: ${userAgent}`);
67+
}
68+
6269
// Skip if already requesting a markdown file
6370
if (url.pathname.endsWith('.md')) {
6471
return undefined;
@@ -76,6 +83,9 @@ const handleAIClientRedirect = (request: NextRequest) => {
7683
const isAIClient = isAIOrDevTool(userAgent);
7784

7885
if (isAIClient || forceMarkdown) {
86+
// Log the redirect for debugging
87+
console.log(`[Middleware] Redirecting to markdown: ${isAIClient ? 'AI client detected' : 'Manual format=md'}`);
88+
7989
// Create new URL with .md extension
8090
const newUrl = url.clone();
8191
// Handle root path and ensure proper .md extension

0 commit comments

Comments
 (0)