import { NextResponse } from 'next/server'

export async function GET() {
    try {
        const strapiBaseUrl = process.env.NEXT_PUBLIC_STRAPI_BASE_URL || process.env.NEW_STRAPI_URL || "http://160.187.167.213"
        const baseUrl = strapiBaseUrl.replace(/\/+$/, "")
        
        const res = await fetch(`${baseUrl}/api/logo?populate=*`, {
            headers: { 
                Accept: "application/json",
            },
            next: { revalidate: 300 } // Cache for 5 minutes
        })

        if (!res.ok) {
            throw new Error(`Strapi logo status ${res.status}`)
        }

        const json = await res.json()
        
        return NextResponse.json(json, {
            headers: {
                'Cache-Control': 'public, s-maxage=300, stale-while-revalidate=600',
            },
        })
    } catch (error) {
        console.error('Error fetching logo:', error)
        return NextResponse.json({ error: 'Failed to fetch logo' }, { status: 500 })
    }
}

