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
- 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>
95 lines
2.8 KiB
TypeScript
95 lines
2.8 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
|
|
const BACKEND_URL = process.env.BACKEND_URL || 'http://backend-compliance:8002'
|
|
|
|
/**
|
|
* Proxy to backend-compliance /api/modules endpoint.
|
|
* Returns the list of service modules from the database.
|
|
*/
|
|
export async function GET(request: NextRequest) {
|
|
try {
|
|
const { searchParams } = new URL(request.url)
|
|
const params = new URLSearchParams()
|
|
|
|
// Forward filter params
|
|
const serviceType = searchParams.get('service_type')
|
|
const criticality = searchParams.get('criticality')
|
|
const processesPii = searchParams.get('processes_pii')
|
|
const aiComponents = searchParams.get('ai_components')
|
|
|
|
if (serviceType) params.set('service_type', serviceType)
|
|
if (criticality) params.set('criticality', criticality)
|
|
if (processesPii) params.set('processes_pii', processesPii)
|
|
if (aiComponents) params.set('ai_components', aiComponents)
|
|
|
|
const queryString = params.toString()
|
|
const url = `${BACKEND_URL}/api/compliance/modules${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()
|
|
console.error('Backend modules error:', errorText)
|
|
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 modules from backend:', error)
|
|
return NextResponse.json(
|
|
{ error: 'Failed to connect to backend' },
|
|
{ status: 503 }
|
|
)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Proxy: POST /api/sdk/v1/modules → Backend POST /api/modules
|
|
* Creates a new custom module.
|
|
*/
|
|
export async function POST(request: NextRequest) {
|
|
try {
|
|
const body = await request.json()
|
|
|
|
const response = await fetch(`${BACKEND_URL}/api/compliance/modules`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
...(request.headers.get('X-Tenant-ID') && {
|
|
'X-Tenant-ID': request.headers.get('X-Tenant-ID') as string,
|
|
}),
|
|
},
|
|
body: JSON.stringify(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 create module:', error)
|
|
return NextResponse.json(
|
|
{ error: 'Failed to connect to backend' },
|
|
{ status: 503 }
|
|
)
|
|
}
|
|
}
|