Data Fetching
Fetch inside frontmatter to run at build-time (SSG) or request-time (SSR):
---const res = await fetch('https://api.example.com/posts');const posts = await res.json();---<ul> {posts.map((p) => <li>{p.title}</li>)}
</ul>
For static sites, the fetch runs during npm run build
. To enable SSR, configure an adapter and set output: 'server'
in astro.config.*
.