Skip to content

Commit

Permalink
Fix dynamic server usage in app router docs route
Browse files Browse the repository at this point in the history
Currently in the app router docs route we read the request
headers directly from the original request object. This is
problematic because it leads to a dynamic server usage
error unless the docs endpoint is explicitly set to `force-dynamic`
caching strategy. By reading the headers from a cloned request
object the docs endpoint can be used with the default caching
strategy, fixing this issue.
  • Loading branch information
blomqma committed May 10, 2024
1 parent 2feaca1 commit 5b1a58f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/next-rest-framework/src/app-router/docs-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ import {
export const docsRoute = (_config?: NextRestFrameworkConfig) => {
const config = getConfig(_config);

const handler = async (req: NextRequest, _context: { params: BaseQuery }) => {
const handler = async (
_req: NextRequest,
_context: { params: BaseQuery }
) => {
try {
const host = req.headers.get('host') ?? '';
const host = _req.clone().headers.get('host') ?? '';
const html = getHtmlForDocs({ config, host });

return new NextResponse(html, {
Expand Down

0 comments on commit 5b1a58f

Please sign in to comment.