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

33 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 response = await fetch(`${baseUrl}/api/schoolforschools?populate=*`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
next: { revalidate: 300 } // Cache for 5 minutes
})
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`)
}
const json = await response.json()
return NextResponse.json(json, {
headers: {
'Cache-Control': 'public, s-maxage=300, stale-while-revalidate=600',
},
})
} catch (error) {
console.error('Error fetching main hero content:', error)
return NextResponse.json({ error: 'Failed to fetch content' }, { status: 500 })
}
}