32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
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/testimonials?populate=avatar`, {
|
|
headers: {
|
|
Accept: "application/json",
|
|
},
|
|
next: { revalidate: 300 } // Cache for 5 minutes
|
|
})
|
|
|
|
if (!res.ok) {
|
|
throw new Error(`Strapi testimonials 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 testimonials:', error)
|
|
return NextResponse.json({ error: 'Failed to fetch testimonials' }, { status: 500 })
|
|
}
|
|
}
|
|
|