dynamic routes for main page

This commit is contained in:
2025-05-23 11:48:45 +03:00
parent efccb591ff
commit 45e5e78df2
10 changed files with 234 additions and 141 deletions

View File

@@ -0,0 +1,24 @@
import { SearchCardProps } from '@/app/types'
export async function getFirstRoutes(): Promise<SearchCardProps[]> {
const API_URL = process.env.NEXT_PUBLIC_API_URL
try {
const response = await fetch(`${API_URL}/latest-routes/`, {
next: {
revalidate: 86400, // один день
},
})
if (!response.ok) {
console.error('Failed to fetch latest routes:', response.statusText)
return []
}
const routes = (await response.json()) as SearchCardProps[]
return Array.isArray(routes) ? routes : []
} catch (error) {
console.error('Error fetching latest routes:', error)
return []
}
}