@devries-cameron20 / composio Mirror · read-only / commits / c0ae64b1f
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 22, 14:30 UTC

Add API proxy to fix CORS issues in API reference playground

Sushmithamallesh committed Jan 22, 2026 at 12:46 UTC c0ae64b1f032f271240a9108f101487fc6a5fbd0
2 files changed +83 -1
docs/app/api/proxy/route.ts new
+80
@@ -0,0 +1,80 @@
1 +import { NextRequest, NextResponse } from 'next/server';
2 +
3 +export async function POST(request: NextRequest) {
4 + return handleProxy(request);
5 +}
6 +
7 +export async function GET(request: NextRequest) {
8 + return handleProxy(request);
9 +}
10 +
11 +export async function PUT(request: NextRequest) {
12 + return handleProxy(request);
13 +}
14 +
15 +export async function DELETE(request: NextRequest) {
16 + return handleProxy(request);
17 +}
18 +
19 +export async function PATCH(request: NextRequest) {
20 + return handleProxy(request);
21 +}
22 +
23 +async function handleProxy(request: NextRequest) {
24 + try {
25 + const url = new URL(request.url);
26 + const targetUrl = url.searchParams.get('url');
27 +
28 + if (!targetUrl) {
29 + return NextResponse.json({ error: 'Missing url parameter' }, { status: 400 });
30 + }
31 +
32 + // Get request body for non-GET requests
33 + let body: string | undefined;
34 + if (request.method !== 'GET' && request.method !== 'HEAD') {
35 + body = await request.text();
36 + }
37 +
38 + // Forward headers (excluding host and other problematic headers)
39 + const headers = new Headers();
40 + request.headers.forEach((value, key) => {
41 + const lowerKey = key.toLowerCase();
42 + if (!['host', 'connection', 'content-length'].includes(lowerKey)) {
43 + headers.set(key, value);
44 + }
45 + });
46 +
47 + const response = await fetch(targetUrl, {
48 + method: request.method,
49 + headers,
50 + body,
51 + });
52 +
53 + const responseBody = await response.text();
54 +
55 + return new NextResponse(responseBody, {
56 + status: response.status,
57 + headers: {
58 + 'Content-Type': response.headers.get('Content-Type') || 'application/json',
59 + 'Access-Control-Allow-Origin': '*',
60 + },
61 + });
62 + } catch (error) {
63 + console.error('Proxy error:', error);
64 + return NextResponse.json(
65 + { error: 'Proxy request failed' },
66 + { status: 500 }
67 + );
68 + }
69 +}
70 +
71 +export async function OPTIONS() {
72 + return new NextResponse(null, {
73 + status: 200,
74 + headers: {
75 + 'Access-Control-Allow-Origin': '*',
76 + 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
77 + 'Access-Control-Allow-Headers': 'Content-Type, Authorization, x-api-key',
78 + },
79 + });
80 +}
docs/components/api-page.client.tsx
+3 -1
@@ -1,4 +1,6 @@
1 'use client';
2 import { defineClientConfig } from 'fumadocs-openapi/ui/client';
3
4 -export default defineClientConfig({});
4 +export default defineClientConfig({
5 + proxyUrl: '/api/proxy',
6 +});