Files
breakpilot-compliance/admin-compliance/app/api/sdk/v1/screening/route.ts
Benjamin Admin 0c75182fb3
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 30s
CI / test-python-backend-compliance (push) Successful in 32s
CI / test-python-document-crawler (push) Successful in 23s
CI / test-python-dsms-gateway (push) Successful in 18s
fix(proxy): 3 kaputte Proxy-Pfade + 21x localhost→backend-compliance Fallback
- compliance-scope: /api/v1/compliance-scope → /api/compliance/v1/compliance-scope
- modules (4 Dateien): /api/modules → /api/compliance/modules
- 21 Proxy-Dateien: localhost:8002 → backend-compliance:8002 Fallback

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 22:57:03 +01:00

92 lines
2.6 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server'
const BACKEND_URL = process.env.BACKEND_URL || 'http://backend-compliance:8002'
/**
* Proxy: GET /api/sdk/v1/screening → Backend GET /api/v1/screening
* Lists screenings for the current tenant.
*/
export async function GET(request: NextRequest) {
try {
const { searchParams } = new URL(request.url)
const queryString = searchParams.toString()
const url = `${BACKEND_URL}/api/v1/screening${queryString ? `?${queryString}` : ''}`
const response = await fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
...(request.headers.get('X-Tenant-ID') && {
'X-Tenant-ID': request.headers.get('X-Tenant-ID') as string,
}),
},
})
if (!response.ok) {
const errorText = await response.text()
return NextResponse.json(
{ error: 'Backend error', details: errorText },
{ status: response.status }
)
}
const data = await response.json()
return NextResponse.json(data)
} catch (error) {
console.error('Failed to fetch screenings:', error)
return NextResponse.json(
{ error: 'Failed to connect to backend' },
{ status: 503 }
)
}
}
/**
* Proxy: POST /api/sdk/v1/screening → Backend POST /api/v1/screening/scan
* Uploads a dependency file (package-lock.json, requirements.txt, etc.) for SBOM + vulnerability scan.
*/
export async function POST(request: NextRequest) {
try {
const contentType = request.headers.get('content-type') || ''
const url = `${BACKEND_URL}/api/v1/screening/scan`
let body: BodyInit
const headers: Record<string, string> = {}
if (contentType.includes('multipart/form-data')) {
body = await request.arrayBuffer()
headers['Content-Type'] = contentType
} else {
body = await request.text()
headers['Content-Type'] = 'application/json'
}
if (request.headers.get('X-Tenant-ID')) {
headers['X-Tenant-ID'] = request.headers.get('X-Tenant-ID') as string
}
const response = await fetch(url, {
method: 'POST',
headers,
body,
})
if (!response.ok) {
const errorText = await response.text()
return NextResponse.json(
{ error: 'Backend error', details: errorText },
{ status: response.status }
)
}
const data = await response.json()
return NextResponse.json(data)
} catch (error) {
console.error('Failed to upload file for screening scan:', error)
return NextResponse.json(
{ error: 'Failed to connect to backend' },
{ status: 503 }
)
}
}