mirror of
https://github.com/aljazceru/enclava.git
synced 2025-12-17 23:44:24 +01:00
37 lines
978 B
TypeScript
37 lines
978 B
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
|
|
const BACKEND_URL = process.env.INTERNAL_API_URL || 'http://enclava-backend:8000'
|
|
|
|
export async function GET(request: NextRequest) {
|
|
try {
|
|
const token = request.headers.get('authorization')
|
|
|
|
if (!token) {
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
|
}
|
|
|
|
const response = await fetch(`${BACKEND_URL}/api/chatbot/list`, {
|
|
method: 'GET',
|
|
headers: {
|
|
'Authorization': token,
|
|
'Content-Type': 'application/json',
|
|
},
|
|
})
|
|
|
|
if (!response.ok) {
|
|
const errorData = await response.text()
|
|
return NextResponse.json(
|
|
{ error: 'Failed to fetch chatbots', details: errorData },
|
|
{ status: response.status }
|
|
)
|
|
}
|
|
|
|
const data = await response.json()
|
|
return NextResponse.json(data)
|
|
} catch (error) {
|
|
return NextResponse.json(
|
|
{ error: 'Internal server error' },
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
} |