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
Add API proxy to fix CORS issues in API reference playground
Sushmithamalleshc0ae64b1f032
diff --git a/docs/app/api/proxy/route.ts b/docs/app/api/proxy/route.tsnew file mode 100644index 000000000..ed23413c4--- /dev/null+++ b/docs/app/api/proxy/route.ts@@ -0,0 +1,80 @@+import { NextRequest, NextResponse } from 'next/server';++export async function POST(request: NextRequest) {+ return handleProxy(request);+}++export async function GET(request: NextRequest) {+ return handleProxy(request);+}++export async function PUT(request: NextRequest) {+ return handleProxy(request);+}++export async function DELETE(request: NextRequest) {+ return handleProxy(request);+}++export async function PATCH(request: NextRequest) {+ return handleProxy(request);+}++async function handleProxy(request: NextRequest) {+ try {+ const url = new URL(request.url);+ const targetUrl = url.searchParams.get('url');++ if (!targetUrl) {+ return NextResponse.json({ error: 'Missing url parameter' }, { status: 400 });+ }++ // Get request body for non-GET requests+ let body: string | undefined;+ if (request.method !== 'GET' && request.method !== 'HEAD') {+ body = await request.text();+ }++ // Forward headers (excluding host and other problematic headers)+ const headers = new Headers();+ request.headers.forEach((value, key) => {+ const lowerKey = key.toLowerCase();+ if (!['host', 'connection', 'content-length'].includes(lowerKey)) {+ headers.set(key, value);+ }+ });++ const response = await fetch(targetUrl, {+ method: request.method,+ headers,+ body,+ });++ const responseBody = await response.text();++ return new NextResponse(responseBody, {+ status: response.status,+ headers: {+ 'Content-Type': response.headers.get('Content-Type') || 'application/json',+ 'Access-Control-Allow-Origin': '*',+ },+ });+ } catch (error) {+ console.error('Proxy error:', error);+ return NextResponse.json(+ { error: 'Proxy request failed' },+ { status: 500 }+ );+ }+}++export async function OPTIONS() {+ return new NextResponse(null, {+ status: 200,+ headers: {+ 'Access-Control-Allow-Origin': '*',+ 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',+ 'Access-Control-Allow-Headers': 'Content-Type, Authorization, x-api-key',+ },+ });+}diff --git a/docs/components/api-page.client.tsx b/docs/components/api-page.client.tsxindex de03e68e0..2abe91303 100644--- a/docs/components/api-page.client.tsx+++ b/docs/components/api-page.client.tsx@@ -1,4 +1,6 @@'use client';import { defineClientConfig } from 'fumadocs-openapi/ui/client';-export default defineClientConfig({});+export default defineClientConfig({+ proxyUrl: '/api/proxy',+});