79 lines
2.2 KiB
TypeScript
79 lines
2.2 KiB
TypeScript
// app/api/diffs/[...path]/route.ts
|
|
import { NextRequest, NextResponse } from 'next/server';
|
|
|
|
const GIT_INTEGRATION_URL = process.env.GIT_INTEGRATION_URL || 'http://localhost:8012';
|
|
|
|
export async function GET(
|
|
request: NextRequest,
|
|
{ params }: { params: { path: string[] } }
|
|
) {
|
|
try {
|
|
const path = params.path.join('/');
|
|
const url = new URL(request.url);
|
|
const searchParams = url.searchParams.toString();
|
|
const fullUrl = `${GIT_INTEGRATION_URL}/api/diffs/${path}${searchParams ? `?${searchParams}` : ''}`;
|
|
|
|
const response = await fetch(fullUrl, {
|
|
method: 'GET',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error(`Git integration service responded with status: ${response.status}`);
|
|
}
|
|
|
|
const data = await response.json();
|
|
return NextResponse.json(data);
|
|
} catch (error) {
|
|
console.error('Error proxying diff request:', error);
|
|
return NextResponse.json(
|
|
{
|
|
success: false,
|
|
message: 'Failed to fetch diff data',
|
|
error: error instanceof Error ? error.message : 'Unknown error'
|
|
},
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|
|
|
|
export async function POST(
|
|
request: NextRequest,
|
|
{ params }: { params: { path: string[] } }
|
|
) {
|
|
try {
|
|
const path = params.path.join('/');
|
|
const body = await request.json();
|
|
const url = new URL(request.url);
|
|
const searchParams = url.searchParams.toString();
|
|
const fullUrl = `${GIT_INTEGRATION_URL}/api/diffs/${path}${searchParams ? `?${searchParams}` : ''}`;
|
|
|
|
const response = await fetch(fullUrl, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify(body),
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error(`Git integration service responded with status: ${response.status}`);
|
|
}
|
|
|
|
const data = await response.json();
|
|
return NextResponse.json(data);
|
|
} catch (error) {
|
|
console.error('Error proxying diff request:', error);
|
|
return NextResponse.json(
|
|
{
|
|
success: false,
|
|
message: 'Failed to process diff request',
|
|
error: error instanceof Error ? error.message : 'Unknown error'
|
|
},
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|