Files
konstitisyon.nu/app/page.js
T

46 lines
997 B
JavaScript
Raw Normal View History

2024-05-17 08:29:06 +04:00
import {createDirectus, rest, readItems} from '@directus/sdk'
2024-05-16 19:38:20 +04:00
import {Typography} from '@mui/material'
2024-05-17 08:29:06 +04:00
import {formatKonstitisyon} from '../lib/format.js'
async function getData() {
const apiUrl = process.env.DIRECTUS_API_URL
if (!apiUrl) {
throw new Error('DIRECTUS_API_URL is required')
}
const client = createDirectus(apiUrl).with(rest())
try {
const titres = await client.request(
readItems('titres', {
sort: 'numero'
})
)
const articles = await client.request(
readItems('articles', {
sort: 'numero'
})
)
if (titres.length === 0 || articles.length === 0) {
throw new Error('No data')
}
const konstitisyon = formatKonstitisyon(titres, articles)
return konstitisyon
} catch {
throw new Error('Failed to fetch data')
}
}
export default async function Page() {
const data = await getData()
console.log('data', data)
2024-05-16 19:38:20 +04:00
return <Typography variant='h1'>konstitisyon.la</Typography>
2024-05-16 02:17:33 +04:00
}