From 7d9659207ddeef9a304436d66e17c98965d6ad59 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 31 Jul 2025 14:49:28 +0000 Subject: [PATCH] Fix Copy Page Dropdown 404 errors in production - Replace runtime file system access with pre-built docs.json approach - Follow same pattern as llms.txt route for Cloudflare Workers compatibility - Maintain same API interface for frontend component - Add path matching logic for both direct and index.mdx patterns Fixes #239 production 404 errors by using build-time generated JSON instead of Node.js fs operations that don't work in Cloudflare Workers. Co-Authored-By: srith@agentuity.com --- app/api/page-content/route.ts | 40 +++++++++++++++++------------------ 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/app/api/page-content/route.ts b/app/api/page-content/route.ts index d3d242f1..3b71c853 100644 --- a/app/api/page-content/route.ts +++ b/app/api/page-content/route.ts @@ -1,7 +1,13 @@ import { NextRequest } from 'next/server'; -import { readFile } from 'fs/promises'; -import { join } from 'path'; -import matter from 'gray-matter'; +import docsJson from '@/content/docs.json'; + +interface Doc { + file: string; + meta: Record; + content: string; +} + +const docs = docsJson.docs as Doc[]; export async function GET(request: NextRequest) { try { @@ -16,28 +22,20 @@ export async function GET(request: NextRequest) { return new Response('Invalid path parameter', { status: 400 }); } - const basePath = join(process.cwd(), 'content'); - const indexPath = join(basePath, path, 'index.mdx'); - const directPath = join(basePath, `${path}.mdx`); + const doc = docs.find(d => + d.file === `${path}.mdx` || + d.file === `${path}/index.mdx` || + d.file === path + ); - let fileContent: string; - - try { - fileContent = await readFile(indexPath, 'utf-8'); - } catch { - try { - fileContent = await readFile(directPath, 'utf-8'); - } catch { - return new Response('Page not found', { status: 404 }); - } + if (!doc) { + return new Response('Page not found', { status: 404 }); } - const { content, data } = matter(fileContent); - return Response.json({ - content, - title: data.title || '', - description: data.description || '', + content: doc.content, + title: doc.meta.title || '', + description: doc.meta.description || '', path }); } catch (error) {