dynamic routes for main page
This commit is contained in:
24
frontend/lib/main/fetchFirstRoutes.ts
Normal file
24
frontend/lib/main/fetchFirstRoutes.ts
Normal 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 []
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user