mirror of
https://github.com/aljazceru/enclava.git
synced 2025-12-17 07:24:34 +01:00
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
|
|
export async function GET(request: NextRequest) {
|
|
try {
|
|
// Extract authorization header from the incoming request
|
|
const authHeader = request.headers.get('authorization')
|
|
|
|
if (!authHeader) {
|
|
return NextResponse.json(
|
|
{ error: 'Authorization header required' },
|
|
{ status: 401 }
|
|
)
|
|
}
|
|
|
|
// Make request to backend Zammad chatbots endpoint
|
|
const baseUrl = process.env.INTERNAL_API_URL || process.env.NEXT_PUBLIC_API_URL
|
|
const url = `${baseUrl}/api/zammad/chatbots`
|
|
|
|
const response = await fetch(url, {
|
|
method: 'GET',
|
|
headers: {
|
|
'Authorization': authHeader,
|
|
'Content-Type': 'application/json'
|
|
}
|
|
})
|
|
|
|
const data = await response.json()
|
|
|
|
if (!response.ok) {
|
|
return NextResponse.json(data, { status: response.status })
|
|
}
|
|
|
|
return NextResponse.json(data)
|
|
} catch (error) {
|
|
console.error('Error fetching Zammad chatbots:', error)
|
|
return NextResponse.json(
|
|
{ error: 'Failed to fetch Zammad chatbots' },
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
} |