Skip to content

Commit 2661a20

Browse files
committed
Moving LLM generation functionality out of middleware and into nextjs config
1 parent 8a5474e commit 2661a20

File tree

2 files changed

+11
-31
lines changed

2 files changed

+11
-31
lines changed

redirects.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ const isDeveloperDocs = !!process.env.NEXT_PUBLIC_DEVELOPER_DOCS;
22

33
/** @type {import('next/dist/lib/load-custom-routes').Redirect[]} */
44
const developerDocsRedirects = [
5+
// LLMs.txt redirect - converts any page to markdown format
6+
{
7+
source: '/:path*/llms.txt',
8+
destination: '/api/llms-txt/:path*',
9+
},
510
{
611
source: '/sdk/miscellaneous/unified-api/tracing/:path*',
712
destination: '/sdk/performance/:path*',
@@ -218,6 +223,11 @@ const developerDocsRedirects = [
218223

219224
/** @type {import('next/dist/lib/load-custom-routes').Redirect[]} */
220225
const userDocsRedirects = [
226+
// LLMs.txt redirect - converts any page to markdown format
227+
{
228+
source: '/:path*/llms.txt',
229+
destination: '/api/llms-txt/:path*',
230+
},
221231
{
222232
source: '/organization/integrations/telegram-alerts-bot/',
223233
destination: '/organization/integrations/notification-incidents/telegram-alerts-bot/',

src/middleware.ts

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ export const config = {
1919

2020
// This function can be marked `async` if using `await` inside
2121
export function middleware(request: NextRequest) {
22-
// Check if the URL ends with llms.txt
23-
if (request.nextUrl.pathname.endsWith('llms.txt')) {
24-
return handleLlmsTxt(request);
25-
}
26-
22+
// Remove the llms.txt handling - it's now handled by Next.js redirects
2723
return handleRedirects(request);
2824
}
2925

@@ -67,32 +63,6 @@ const handleRedirects = (request: NextRequest) => {
6763
return undefined;
6864
};
6965

70-
const handleLlmsTxt = async (request: NextRequest) => {
71-
try {
72-
// Get the original path by removing llms.txt
73-
const originalPath = request.nextUrl.pathname.replace(/\/llms\.txt$/, '') || '/';
74-
const pathSegments = originalPath.split('/').filter(Boolean);
75-
76-
// Rewrite to the API route with path segments
77-
const apiPath =
78-
pathSegments.length > 0
79-
? `/api/llms-txt/${pathSegments.join('/')}`
80-
: '/api/llms-txt';
81-
82-
const apiUrl = new URL(apiPath, request.url);
83-
84-
return NextResponse.rewrite(apiUrl);
85-
} catch (error) {
86-
console.error('Error handling llms.txt rewrite:', error);
87-
return new Response('Error processing request', {
88-
status: 500,
89-
headers: {
90-
'Content-Type': 'text/plain; charset=utf-8',
91-
},
92-
});
93-
}
94-
};
95-
9666
type Redirect = {
9767
/** a string with a leading and a trailing slash */
9868
from: `/${string}/` | '/';

0 commit comments

Comments
 (0)