Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
fix(docs): move API reference redirect to proxy.ts
Sushmithamallesh3165eb0bcd9f
diff --git a/docs/middleware.ts b/docs/middleware.tsdeleted file mode 100644index 7ed563bbd..000000000--- a/docs/middleware.ts+++ /dev/null@@ -1,63 +0,0 @@-import { NextResponse } from 'next/server';-import type { NextRequest } from 'next/server';--/**- * Convert kebab-case to camelCase- */-function kebabToCamel(str: string): string {- return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());-}--/**- * Check if a string contains kebab-case (has hyphens between lowercase letters)- */-function hasKebabCase(str: string): boolean {- return /[a-z]-[a-z]/.test(str);-}--export function middleware(request: NextRequest) {- const { pathname } = request.nextUrl;-- // Only handle API reference paths- if (!pathname.startsWith('/reference/api-reference/')) {- return NextResponse.next();- }-- // Check if any path segment has kebab-case- const segments = pathname.split('/');- let hasKebab = false;-- for (const segment of segments) {- if (hasKebabCase(segment)) {- hasKebab = true;- break;- }- }-- if (!hasKebab) {- return NextResponse.next();- }-- // Convert kebab-case segments to camelCase- const newSegments = segments.map((segment, index) => {- // Only convert segments after 'api-reference' (skip the tag/category names)- // api-reference structure: /reference/api-reference/{tag}/{operationId}- if (index <= 3) return segment; // Keep /reference/api-reference/{tag} as-is- return kebabToCamel(segment);- });-- const newPathname = newSegments.join('/');-- // Only redirect if the path actually changed- if (newPathname !== pathname) {- const url = request.nextUrl.clone();- url.pathname = newPathname;- return NextResponse.redirect(url, 301);- }-- return NextResponse.next();-}--export const config = {- matcher: '/reference/api-reference/:path*',-};diff --git a/docs/proxy.ts b/docs/proxy.tsindex 4be335cdc..ceb10962c 100644--- a/docs/proxy.ts+++ b/docs/proxy.ts@@ -1,17 +1,65 @@import { NextRequest, NextResponse } from 'next/server';/**- * Serves markdown when AI agents request it via Accept: text/markdown header.- * Test: curl -H "Accept: text/markdown" http://localhost:3000/docs/quickstart+ * Convert kebab-case to camelCase+ */+function kebabToCamel(str: string): string {+ return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());+}++/**+ * Check if a string contains kebab-case (has hyphens between lowercase letters)+ */+function hasKebabCase(str: string): boolean {+ return /[a-z]-[a-z]/.test(str);+}++/**+ * Proxy handles:+ * 1. Markdown content negotiation for AI agents (Accept: text/markdown)+ * 2. Redirects for old Fern API reference URLs (kebab-case → camelCase)*/export function proxy(request: NextRequest) {+ const { pathname } = request.nextUrl;const accept = request.headers.get('accept') || '';+ // Handle markdown content negotiation for AI agentsif (accept.includes('text/markdown') || accept.includes('text/plain')) {- const mdUrl = new URL(`/llms.mdx${request.nextUrl.pathname}`, request.nextUrl.origin);+ const mdUrl = new URL(`/llms.mdx${pathname}`, request.nextUrl.origin);return NextResponse.rewrite(mdUrl);}+ // Handle old Fern API reference URLs (kebab-case → camelCase)+ // Example: /reference/api-reference/tools/get-tools → /reference/api-reference/tools/getTools+ if (pathname.startsWith('/reference/api-reference/')) {+ const segments = pathname.split('/');+ let hasKebab = false;++ // Check if any segment after the tag has kebab-case+ // Structure: /reference/api-reference/{tag}/{operationId}+ for (let i = 4; i < segments.length; i++) {+ if (hasKebabCase(segments[i])) {+ hasKebab = true;+ break;+ }+ }++ if (hasKebab) {+ // Convert kebab-case segments to camelCase (only operation IDs, not tags)+ const newSegments = segments.map((segment, index) => {+ if (index <= 3) return segment; // Keep /reference/api-reference/{tag} as-is+ return kebabToCamel(segment);+ });++ const newPathname = newSegments.join('/');+ if (newPathname !== pathname) {+ const url = request.nextUrl.clone();+ url.pathname = newPathname;+ return NextResponse.redirect(url, 301);+ }+ }+ }+return NextResponse.next();}