Some checks failed
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-go-ai-compliance (push) Failing after 33s
CI / test-python-backend-compliance (push) Successful in 34s
CI / test-python-document-crawler (push) Successful in 24s
CI / test-python-dsms-gateway (push) Successful in 27s
The backend routes are nested under /api/compliance/ prefix, not /api/. Also includes Suspense boundary fix for useSearchParams in layout. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
121 lines
3.3 KiB
TypeScript
121 lines
3.3 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
|
|
const BACKEND_URL = process.env.BACKEND_URL || 'http://backend-compliance:8002'
|
|
|
|
/**
|
|
* Proxy: GET /api/sdk/v1/projects/{projectId} → Backend
|
|
*/
|
|
export async function GET(
|
|
request: NextRequest,
|
|
{ params }: { params: Promise<{ projectId: string }> }
|
|
) {
|
|
try {
|
|
const { projectId } = await params
|
|
const tenantId = request.headers.get('X-Tenant-ID') ||
|
|
new URL(request.url).searchParams.get('tenant_id') || ''
|
|
|
|
const response = await fetch(
|
|
`${BACKEND_URL}/api/compliance/v1/projects/${projectId}?tenant_id=${encodeURIComponent(tenantId)}`,
|
|
{
|
|
headers: { 'X-Tenant-ID': tenantId },
|
|
}
|
|
)
|
|
|
|
if (!response.ok) {
|
|
const errorText = await response.text()
|
|
return NextResponse.json(
|
|
{ error: 'Backend error', details: errorText },
|
|
{ status: response.status }
|
|
)
|
|
}
|
|
|
|
return NextResponse.json(await response.json())
|
|
} catch (error) {
|
|
console.error('Failed to get project:', error)
|
|
return NextResponse.json(
|
|
{ error: 'Failed to connect to backend' },
|
|
{ status: 503 }
|
|
)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Proxy: PATCH /api/sdk/v1/projects/{projectId} → Backend
|
|
*/
|
|
export async function PATCH(
|
|
request: NextRequest,
|
|
{ params }: { params: Promise<{ projectId: string }> }
|
|
) {
|
|
try {
|
|
const { projectId } = await params
|
|
const body = await request.json()
|
|
const tenantId = body.tenant_id || request.headers.get('X-Tenant-ID') || ''
|
|
|
|
const response = await fetch(
|
|
`${BACKEND_URL}/api/compliance/v1/projects/${projectId}?tenant_id=${encodeURIComponent(tenantId)}`,
|
|
{
|
|
method: 'PATCH',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'X-Tenant-ID': tenantId,
|
|
},
|
|
body: JSON.stringify(body),
|
|
}
|
|
)
|
|
|
|
if (!response.ok) {
|
|
const errorText = await response.text()
|
|
return NextResponse.json(
|
|
{ error: 'Backend error', details: errorText },
|
|
{ status: response.status }
|
|
)
|
|
}
|
|
|
|
return NextResponse.json(await response.json())
|
|
} catch (error) {
|
|
console.error('Failed to update project:', error)
|
|
return NextResponse.json(
|
|
{ error: 'Failed to connect to backend' },
|
|
{ status: 503 }
|
|
)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Proxy: DELETE /api/sdk/v1/projects/{projectId} → Backend (soft delete)
|
|
*/
|
|
export async function DELETE(
|
|
request: NextRequest,
|
|
{ params }: { params: Promise<{ projectId: string }> }
|
|
) {
|
|
try {
|
|
const { projectId } = await params
|
|
const tenantId = request.headers.get('X-Tenant-ID') ||
|
|
new URL(request.url).searchParams.get('tenant_id') || ''
|
|
|
|
const response = await fetch(
|
|
`${BACKEND_URL}/api/compliance/v1/projects/${projectId}?tenant_id=${encodeURIComponent(tenantId)}`,
|
|
{
|
|
method: 'DELETE',
|
|
headers: { 'X-Tenant-ID': tenantId },
|
|
}
|
|
)
|
|
|
|
if (!response.ok) {
|
|
const errorText = await response.text()
|
|
return NextResponse.json(
|
|
{ error: 'Backend error', details: errorText },
|
|
{ status: response.status }
|
|
)
|
|
}
|
|
|
|
return NextResponse.json(await response.json())
|
|
} catch (error) {
|
|
console.error('Failed to archive project:', error)
|
|
return NextResponse.json(
|
|
{ error: 'Failed to connect to backend' },
|
|
{ status: 503 }
|
|
)
|
|
}
|
|
}
|