Skip to content

Conversation

@sohamganatra
Copy link
Contributor

Summary

Enables AI agents to request pure markdown content from documentation pages.

Features

  • URL extension: /docs/quickstart.md or .mdx
  • Accept header: text/markdown or text/x-markdown
  • Improved llms.txt: Better index for LLM crawlers

New Files

  • lib/mdx-to-markdown.ts - JSX to markdown converter
  • lib/path-validation.ts - Security validation (prevents traversal attacks)
  • proxy.ts - Content negotiation middleware
  • /api/mdx-content/[...path] - Pure markdown API

Test Plan

  • Visit /docs/quickstart.mdx - should return markdown
  • curl -H "Accept: text/markdown" /docs/quickstart - should return markdown
  • Visit /llms.txt - should show improved index

🤖 Generated with Claude Code

Enables AI agents to request pure markdown content via:
- URL extension: /docs/quickstart.md or .mdx
- Accept header: text/markdown

Components:
- lib/mdx-to-markdown.ts - JSX to markdown converter
- lib/path-validation.ts - Security validation
- proxy.ts - Content negotiation middleware
- /api/mdx-content/[...path] - Pure markdown API
- Improved /llms.txt and /llms-full.txt endpoints

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@vercel
Copy link

vercel bot commented Jan 8, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
fumadocs Ready Ready Preview, Comment Jan 8, 2026 4:19am

- Add boundary check to prefix validation (prevents /docsextra matching /docs)
- Add YAML reserved word escaping (true, false, null, yes, no, etc.)
- Add YAML number detection to prevent type coercion
- Fix Callout regex to capture title/type in any order
- Fix Accordion regex to properly capture title attribute

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Fix NaN regex precedence bug (use non-capturing group)
- Fix YouTube/Video/ProviderCard regex to handle attributes in any order

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
const timeoutPromise = new Promise<never>((_, reject) =>
setTimeout(() => reject(new Error('Content retrieval timeout')), 10000)
);
rawContent = await Promise.race([contentPromise, timeoutPromise]);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Timeout promise causes unhandled rejection after successful requests

Medium Severity

The timeoutPromise created with setTimeout is never cancelled when contentPromise resolves first. When content is successfully fetched before the 10-second timeout, Promise.race resolves with the content and the function continues, but the timer keeps running. After 10 seconds, the timeout promise rejects with new Error('Content retrieval timeout'), and since nothing awaits or catches this rejection, it becomes an unhandled promise rejection. This will cause error logs and potentially process termination in Node.js 15+. The timer reference needs to be stored and cleared with clearTimeout when content resolves successfully.

Fix in Cursor Fix in Web

* - Validates paths to prevent traversal attacks
* - Handles double encoding, unicode normalization
*/
export function proxy(request: NextRequest) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Middleware function not exported with correct name for Next.js

High Severity

The file exports a function named proxy and a config with a matcher, but Next.js middleware requires the function to be exported as middleware (either default or named) from a file named middleware.ts at the project root. Currently, proxy.ts exports proxy, which Next.js won't recognize as middleware. The content negotiation feature (.md/.mdx URL extensions and Accept header handling) won't work because requests won't be intercepted. The test plan items like visiting /docs/quickstart.mdx will not return markdown as expected.

Additional Locations (1)

Fix in Cursor Fix in Web

@sohamganatra
Copy link
Contributor Author

Superseded by smaller PRs for easier review:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants