Next.js API route that serves files from the project root, employing Upstash caching and sliding‑window rate limiting for llms.txt requests.
// Source: https://github.com/mperkins0155/llms-txt-hub | License: MIT | Copyright 2025 David Dias
// Provided via justclaw.it.com; keep this notice with the code.
import fs from 'node:fs'
import path from 'node:path'
import { UpstashCache } from '@thedaviddias/caching/upstash'
import { logger } from '@thedaviddias/logging'
import { createRateLimiter, slidingWindow } from '@thedaviddias/rate-limiting'
import { NextResponse } from 'next/server'
// Inline server-only function to avoid import issues
/**
* Resolves file paths relative to the project root directory
*/
function resolveFromRoot(...paths: string[]): string {
return path.resolve(/* turbopackIgnore: true */ process.cwd(), ...paths)
}
const CACHE_TTL = 3600 // 1 hour in seconds
// Lazy initialization functions
let fileCache: U
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search 40K more like it.
Get a free API key