Skip to content

Commit aa427d0

Browse files
committed
enhance: add content type indicators to middleware logging
- Show πŸ“„ MARKDOWN or 🌐 HTML indicators in logs - Determine content type before logging for better debugging - Makes it clear which requests get markdown vs HTML content
1 parent c72e1ab commit aa427d0

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

β€Žsrc/middleware.tsβ€Ž

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,17 @@ const handleAIClientRedirect = (request: NextRequest) => {
6060
const userAgent = request.headers.get('user-agent') || '';
6161
const url = request.nextUrl;
6262

63+
// Determine if this will be served as markdown
64+
const forceMarkdown = url.searchParams.get('format') === 'md';
65+
const isAIClient = isAIOrDevTool(userAgent);
66+
const willServeMarkdown = (isAIClient || forceMarkdown) && !url.pathname.endsWith('.md');
67+
6368
// Log user agent for debugging (only for non-static assets)
6469
if (!url.pathname.startsWith('/_next/') &&
6570
!url.pathname.includes('.') &&
6671
!url.pathname.startsWith('/api/')) {
67-
console.log(`[Middleware] ${url.pathname} - User-Agent: ${userAgent}`);
72+
const contentType = willServeMarkdown ? 'πŸ“„ MARKDOWN' : '🌐 HTML';
73+
console.log(`[Middleware] ${url.pathname} - ${contentType} - User-Agent: ${userAgent}`);
6874
}
6975

7076
// Skip if already requesting a markdown file
@@ -79,9 +85,7 @@ const handleAIClientRedirect = (request: NextRequest) => {
7985
return undefined;
8086
}
8187

82-
// Check for explicit format request via query parameter
83-
const forceMarkdown = url.searchParams.get('format') === 'md';
84-
const isAIClient = isAIOrDevTool(userAgent);
88+
// Check for AI client detection
8589

8690
if (isAIClient || forceMarkdown) {
8791
// Log the redirect for debugging

0 commit comments

Comments
Β (0)