SFS/app/api/trusted-by/route.ts
2025-12-16 10:03:26 +05:30

39 lines
1.5 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(/\/+$/, "")
// Fetch all trusted-by data in parallel
const [headingRes, subtextRes, logosRes] = await Promise.all([
fetch(`${baseUrl}/api/trusted-by-text`, {
headers: { Accept: "application/json" },
next: { revalidate: 300 }
}),
fetch(`${baseUrl}/api/trusted-by-text-description`, {
headers: { Accept: "application/json" },
next: { revalidate: 300 }
}),
fetch(`${baseUrl}/api/trusted-schools?populate=*`, {
headers: { Accept: "application/json" },
next: { revalidate: 300 }
})
])
const heading = headingRes.ok ? await headingRes.json() : null
const subtext = subtextRes.ok ? await subtextRes.json() : null
const logos = logosRes.ok ? await logosRes.json() : null
return NextResponse.json({ heading, subtext, logos }, {
headers: {
'Cache-Control': 'public, s-maxage=300, stale-while-revalidate=600',
},
})
} catch (error) {
console.error('Error fetching trusted-by data:', error)
return NextResponse.json({ error: 'Failed to fetch trusted-by data' }, { status: 500 })
}
}