Fumadocs rebuilt on Hamur, the original is fumadocs.dev
Skip to Content
Fumadocs

Negotiation

Content negotiation utilities.

Overview

For React frameworks supporting middlewares, you can use the Negotiation API of Fumadocs for basic functionalities. On Waku, use it in a Hono middleware in src/middleware. On Astro, use it in a middleware, which only runs for pages rendered on request.

Accept Markdown

Serve markdown or HTML depending on the Accept header, this can improve the experience for AI agents.

proxy.ts
import { NextRequest, NextResponse } from 'next/server';
import { isMarkdownPreferred, rewritePath } from 'fumadocs-core/negotiation';

const { rewrite: rewriteLLM } = rewritePath('/docs/*path', '/llms.mdx/*path');

export default function proxy(request: NextRequest) {
  if (isMarkdownPreferred(request)) {
    const result = rewriteLLM(request.nextUrl.pathname);

    if (result) {
      return NextResponse.rewrite(new URL(result, request.nextUrl));
    }
  }

  return NextResponse.next();
}

How is this guide?

Last updated on