Skip to content

Commit c39c8e5

Browse files
[getsentry/action-github-commit] Auto commit
1 parent aa427d0 commit c39c8e5

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

src/middleware.ts

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ const redirectStatusCode = process.env.NODE_ENV === 'development' ? 302 : 301;
3737
*/
3838
function isAIOrDevTool(userAgent: string): boolean {
3939
const patterns = [
40-
/claude/i, // Claude Desktop/Code
41-
/cursor/i, // Cursor IDE
42-
/copilot/i, // GitHub Copilot
43-
/chatgpt/i, // ChatGPT
44-
/openai/i, // OpenAI tools
45-
/anthropic/i, // Anthropic tools
46-
/vscode/i, // VS Code extensions
47-
/intellij/i, // IntelliJ plugins
48-
/sublime/i, // Sublime Text plugins
49-
/got/i, // Got HTTP library (sindresorhus/got)
40+
/claude/i, // Claude Desktop/Code
41+
/cursor/i, // Cursor IDE
42+
/copilot/i, // GitHub Copilot
43+
/chatgpt/i, // ChatGPT
44+
/openai/i, // OpenAI tools
45+
/anthropic/i, // Anthropic tools
46+
/vscode/i, // VS Code extensions
47+
/intellij/i, // IntelliJ plugins
48+
/sublime/i, // Sublime Text plugins
49+
/got/i, // Got HTTP library (sindresorhus/got)
5050
// Add more patterns as needed
5151
];
5252

@@ -63,14 +63,19 @@ const handleAIClientRedirect = (request: NextRequest) => {
6363
// Determine if this will be served as markdown
6464
const forceMarkdown = url.searchParams.get('format') === 'md';
6565
const isAIClient = isAIOrDevTool(userAgent);
66-
const willServeMarkdown = (isAIClient || forceMarkdown) && !url.pathname.endsWith('.md');
66+
const willServeMarkdown =
67+
(isAIClient || forceMarkdown) && !url.pathname.endsWith('.md');
6768

6869
// Log user agent for debugging (only for non-static assets)
69-
if (!url.pathname.startsWith('/_next/') &&
70-
!url.pathname.includes('.') &&
71-
!url.pathname.startsWith('/api/')) {
70+
if (
71+
!url.pathname.startsWith('/_next/') &&
72+
!url.pathname.includes('.') &&
73+
!url.pathname.startsWith('/api/')
74+
) {
7275
const contentType = willServeMarkdown ? '📄 MARKDOWN' : '🌐 HTML';
73-
console.log(`[Middleware] ${url.pathname} - ${contentType} - User-Agent: ${userAgent}`);
76+
console.log(
77+
`[Middleware] ${url.pathname} - ${contentType} - User-Agent: ${userAgent}`
78+
);
7479
}
7580

7681
// Skip if already requesting a markdown file
@@ -79,17 +84,21 @@ const handleAIClientRedirect = (request: NextRequest) => {
7984
}
8085

8186
// Skip API routes and static assets (should already be filtered by matcher)
82-
if (url.pathname.startsWith('/api/') ||
83-
url.pathname.startsWith('/_next/') ||
84-
url.pathname.includes('.')) {
87+
if (
88+
url.pathname.startsWith('/api/') ||
89+
url.pathname.startsWith('/_next/') ||
90+
url.pathname.includes('.')
91+
) {
8592
return undefined;
8693
}
8794

8895
// Check for AI client detection
8996

9097
if (isAIClient || forceMarkdown) {
9198
// Log the redirect for debugging
92-
console.log(`[Middleware] Redirecting to markdown: ${isAIClient ? 'AI client detected' : 'Manual format=md'}`);
99+
console.log(
100+
`[Middleware] Redirecting to markdown: ${isAIClient ? 'AI client detected' : 'Manual format=md'}`
101+
);
93102

94103
// Create new URL with .md extension
95104
const newUrl = url.clone();

0 commit comments

Comments
 (0)