Skip to content

Commit d0768c4

Browse files
authored
fix(docs): shift rewrite down (#4795)
1 parent 80db87d commit d0768c4

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

packages/fern-docs/bundle/src/middleware.ts

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,40 @@ export const middleware: NextMiddleware = async (request) => {
161161
return rewrite(withDomain(withoutBasepath("/api/fern-docs/")));
162162
}
163163

164+
/**
165+
* Rewrite mcp
166+
*/
167+
if (pathname.endsWith("/_mcp/server")) {
168+
console.log("[middleware] rewriting mcp");
169+
return rewrite(withDomain("/api/fern-docs/mcp"));
170+
}
171+
172+
/**
173+
* Rewrite changelog rss and atom feeds
174+
*/
175+
if (pathname.match(RSS_PATTERN)) {
176+
const format = pathname.match(RSS_PATTERN)?.[1] ?? "rss";
177+
const slug = removeLeadingSlash(withoutEnding(RSS_PATTERN));
178+
// standalone mode does not support search params, so we need to use headers
179+
return rewrite(
180+
withDomain("/api/fern-docs/changelog"),
181+
{ format, slug },
182+
{
183+
"x-fern-changelog-slug": slug,
184+
"x-fern-changelog-format": format
185+
}
186+
);
187+
}
188+
189+
/**
190+
* Rewrite changelog json feed
191+
*/
192+
if (pathname.match(JSON_PATTERN)) {
193+
const format = pathname.match(JSON_PATTERN)?.[1] ?? "json";
194+
const slug = removeLeadingSlash(withoutEnding(JSON_PATTERN));
195+
return rewrite(withDomain("/api/fern-docs/changelog"), { format, slug });
196+
}
197+
164198
/**
165199
* If Accept header contains text/plain or text/markdown,
166200
* serve the llms.txt version instead
@@ -215,40 +249,6 @@ export const middleware: NextMiddleware = async (request) => {
215249
}
216250
}
217251

218-
/**
219-
* Rewrite mcp
220-
*/
221-
if (pathname.endsWith("/_mcp/server")) {
222-
console.log("[middleware] rewriting mcp");
223-
return rewrite(withDomain("/api/fern-docs/mcp"));
224-
}
225-
226-
/**
227-
* Rewrite changelog rss and atom feeds
228-
*/
229-
if (pathname.match(RSS_PATTERN)) {
230-
const format = pathname.match(RSS_PATTERN)?.[1] ?? "rss";
231-
const slug = removeLeadingSlash(withoutEnding(RSS_PATTERN));
232-
// standalone mode does not support search params, so we need to use headers
233-
return rewrite(
234-
withDomain("/api/fern-docs/changelog"),
235-
{ format, slug },
236-
{
237-
"x-fern-changelog-slug": slug,
238-
"x-fern-changelog-format": format
239-
}
240-
);
241-
}
242-
243-
/**
244-
* Rewrite changelog json feed
245-
*/
246-
if (pathname.match(JSON_PATTERN)) {
247-
const format = pathname.match(JSON_PATTERN)?.[1] ?? "json";
248-
const slug = removeLeadingSlash(withoutEnding(JSON_PATTERN));
249-
return rewrite(withDomain("/api/fern-docs/changelog"), { format, slug });
250-
}
251-
252252
/**
253253
* At this point, conform the trailing slash setting or else redirect
254254
*/

0 commit comments

Comments
 (0)