llms.txt in Next.js einbinden - Anleitung
Du möchtest deine llms.txt in Next.js einbinden? Next.js macht es besonders einfach: Statische Dateien im public/ Ordner werden automatisch im Root-Verzeichnis bereitgestellt. Hier sind beide Wege - statisch und dynamisch.
Option 1: Statische Datei (empfohlen)
Der einfachste Weg: Lege deine generierte llms.txt-Datei direkt in den public-Ordner.
my-nextjs-app/ ├── public/ │ ├── llms.txt ← Deine llms.txt │ ├── llms-full.txt ← Optional: Vollversion │ ├── robots.txt │ └── sitemap.xml ├── app/ │ └── ... └── package.json
Nach dem Deployment ist die Datei automatisch unter https://deine-domain.de/llms.txt erreichbar. Keine weitere Konfiguration nötig.
Option 2: Dynamische Route (App Router)
Für dynamisch generierte Inhalte kannst du eine API-Route verwenden:
// app/llms.txt/route.ts
import { NextResponse } from 'next/server'
import fs from 'fs'
import path from 'path'
export async function GET() {
// Variante A: Datei vom Filesystem lesen
const filePath = path.join(process.cwd(), 'data', 'llms.txt')
const content = fs.readFileSync(filePath, 'utf-8')
// Variante B: Dynamisch generieren
// const content = await generateLlmsTxt()
return new NextResponse(content, {
headers: {
'Content-Type': 'text/plain; charset=utf-8',
'Cache-Control': 'public, max-age=86400',
},
})
}Diese Variante eignet sich, wenn du die llms.txt automatisch aus deiner Datenbank oder deinem CMS generieren möchtest.
Option 3: Pages Router
Falls du noch den Pages Router verwendest:
// pages/api/llms-txt.ts
import type { NextApiRequest, NextApiResponse } from 'next'
export default function handler(
req: NextApiRequest,
res: NextApiResponse
) {
const content = '# Meine Website\n> Beschreibung...'
res.setHeader('Content-Type', 'text/plain')
res.status(200).send(content)
}
// Hinweis: Für /llms.txt statt /api/llms-txt
// nutze next.config.js rewrites:
// async rewrites() {
// return [{ source: '/llms.txt', destination: '/api/llms-txt' }]
// }Deployment auf Vercel
Auf Vercel funktioniert die statische Variante ohne jede Konfiguration. Dateien in public/ werden automatisch über das CDN ausgeliefert. Für optimale Performance empfehlen wir die statische Variante mit regelmäßiger Aktualisierung (mindestens einmal pro Quartal).
Verwandte Themen
Bereit, deine Website
LLM-ready zu machen?
Kostenlos bis 20 Seiten. Keine Registrierung. Einfach URL eingeben und starten.